diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 36 | ||||
-rw-r--r-- | perllib/FixMyStreet/Geocode/Google.pm | 28 |
2 files changed, 19 insertions, 45 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index fbf831eb6..687843a2a 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -20,19 +20,7 @@ sub disambiguate_location { my $town = 'Bromley'; - # Helpful regexes that are used often - my $road = 'r(?:oa)?d'; - my $street = 'st(\.|reet)?'; - - # Bing turns High St Bromley into Bromley High St which is in - # Bromley by Bow. - $town .= ', BR1' if $string =~ /^high\s+${street}$/i; - - # Disambiguations required for BR5 - $town .= ', BR5' if $string =~ /^kelsey\s+${road}$/i; - $town = 'BR5 Bromley' if $string =~ /^leith\s+hill$/i; # doesn't like appended BR5 for some reason - - # There has also been a road name change for a section of Ramsden Road + # There has been a road name change for a section of Ramsden Road # (BR5) between Church Hill and Court Road has changed to 'Old Priory # Avenue' - presently entering Old Priory Avenue simply takes the user to # a different Priory Avenue in Petts Wood @@ -41,26 +29,10 @@ sub disambiguate_location { $string = 'Ramsden Road'; $town = ', BR6 0PL'; } - $town .= ', BR5' if $string =~ /^meadway/i; - $town .= ', BR5' if $string =~ /^mill\s+brook\s+${road}$/i; - $town .= ', BR5' if $string =~ /^kent\s+${road}$/i; - $town .= ', BR5' if $string =~ /^the\s+landway$/i; - $town .= ', BR5' if $string =~ /^mountfield\s+way$/i; - $town .= ', BR5 3' if $string =~ /^star\s+lane$/i; - $town .= ', BR5 4AX' if $string =~ /^high\s+${street}?(,)?\s?st\.?\s+mary\s+cray$/i; - - # and BR6 - $town .= ', BR6' if $string =~ /^berrylands/i; - $town .= ', BR6' if $string =~ /^crofton\s+${road}$/i; - $town .= ', BR6' if $string =~ /^crofton\s+lane$/i; # White Horse Hill is on boundary with Greenwich, so need a # specific postcode - $town = 'chislehurst, BR7 6DH' if $string =~ /^white\s+horse/i; - - # Mottingham Lane is 90% inside Bromley, but goes outside too and Bing - # defaults to the top end of it. - $town = 'Mottingham Lane, SE9 4RW' if $string =~ /^mottingham\s+lane/i; + $string = 'BR7 6DH' if $string =~ /^white\s+horse/i; $town = '' if $string =~ /orpington/i; @@ -73,6 +45,10 @@ sub disambiguate_location { }; } +sub get_geocoder { + return 'OSM'; # default of Bing gives poor results, let's try overriding. +} + sub example_places { return ( 'BR1 3UH', 'Glebe Rd, Bromley' ); } diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm index 35fcec36f..5261bb7e4 100644 --- a/perllib/FixMyStreet/Geocode/Google.pm +++ b/perllib/FixMyStreet/Geocode/Google.pm @@ -28,34 +28,32 @@ sub string { $s = FixMyStreet::Geocode::escape($s); - my $url = 'http://maps.google.com/maps/geo?q=' . $s; - $url .= '&ll=' . $params->{centre} if $params->{centre}; - $url .= '&spn=' . $params->{span} if $params->{span}; + my $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $s; + $url .= '&bounds=' . $params->{bounds}[0] . ',' . $params->{bounds}[1] + . '|' . $params->{bounds}[2] . ',' . $params->{bounds}[3] + if $params->{bounds}; if ($params->{google_country}) { - $url .= '&gl=' . $params->{google_country}; + $url .= '®ion=' . $params->{google_country}; } elsif ($params->{country}) { - $url .= '&gl=' . $params->{country}; + $url .= '®ion=' . $params->{country}; } - $url .= '&hl=' . $params->{lang} if $params->{lang}; + $url .= '&language=' . $params->{lang} if $params->{lang}; - my $args = 'sensor=false&key=' . FixMyStreet->config('GOOGLE_MAPS_API_KEY'); - my $js = FixMyStreet::Geocode::cache('google', $url, $args, qr/"code":6[12]0/); + my $args = 'key=' . FixMyStreet->config('GOOGLE_MAPS_API_KEY'); + my $js = FixMyStreet::Geocode::cache('google', $url, $args, qr/"status"\s*:\s*"(OVER_QUERY_LIMIT|REQUEST_DENIED|INVALID_REQUEST|UNKNOWN_ERROR)"/); if (!$js) { return { error => _('Sorry, we could not parse that location. Please try again.') }; } - if ($js->{Status}->{code} ne '200') { - return { error => _('Sorry, we could not find that location.') }; - } + return unless $js->{status} eq 'OK'; - my $results = $js->{Placemark}; + my $results = $js->{results}; my ( $error, @valid_locations, $latitude, $longitude ); foreach (@$results) { - next unless $_->{AddressDetails}->{Accuracy} >= 4; - my $address = $_->{address}; + my $address = $_->{formatted_address}; next unless $c->cobrand->geocoded_string_check( $address ); ( $longitude, $latitude ) = map { Utils::truncate_coordinate($_) } - @{ $_->{Point}->{coordinates} }; + ($_->{geometry}{location}{lat}, $_->{geometry}{location}{lng}); push (@$error, { address => $address, latitude => $latitude, |