aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-01-22 15:57:45 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2015-02-13 11:44:07 +0000
commitda63f72c27e16d491f9103b9a8cbdb2fd96d2b59 (patch)
treecfd6df35b4c41028943d8a1e669345b81be41913 /perllib/FixMyStreet/Geocode
parent04117b8be30b5d82d50cdc047ac4e7c19864f8ed (diff)
Make sure all co-ordinates are stringified.
This includes MapIt postcode lookups, geocoding, query parameters, tile clicks. Stringifying truncates them to six decimal places, which means we no longer need any "short" versions anywhere, and the JSON response will always uses a decimal point regardless of locale.
Diffstat (limited to 'perllib/FixMyStreet/Geocode')
-rw-r--r--perllib/FixMyStreet/Geocode/Bing.pm19
-rw-r--r--perllib/FixMyStreet/Geocode/FixaMinGata.pm42
-rw-r--r--perllib/FixMyStreet/Geocode/Google.pm19
-rw-r--r--perllib/FixMyStreet/Geocode/OSM.pm19
-rw-r--r--perllib/FixMyStreet/Geocode/Zurich.pm18
5 files changed, 53 insertions, 64 deletions
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm
index 702e19814..61e04d3d5 100644
--- a/perllib/FixMyStreet/Geocode/Bing.pm
+++ b/perllib/FixMyStreet/Geocode/Bing.pm
@@ -13,7 +13,7 @@ use File::Path ();
use LWP::Simple;
use Digest::MD5 qw(md5_hex);
-use mySociety::Locale;
+use Utils;
# string STRING CONTEXT
# Looks up on Bing Maps API, and caches, a user-inputted location.
@@ -71,15 +71,14 @@ sub string {
|| $valid_locations[-1]{address}{locality} eq $_->{address}{locality}
);
- ( $latitude, $longitude ) = @{ $_->{point}->{coordinates} };
- # These co-ordinates are output as query parameters in a URL, make sure they have a "."
- mySociety::Locale::in_gb_locale {
- push (@$error, {
- address => $address,
- latitude => sprintf('%0.6f', $latitude),
- longitude => sprintf('%0.6f', $longitude)
- });
- };
+ ( $latitude, $longitude ) =
+ map { Utils::truncate_coordinate($_) }
+ @{ $_->{point}->{coordinates} };
+ push (@$error, {
+ address => $address,
+ latitude => $latitude,
+ longitude => $longitude
+ });
push (@valid_locations, $_);
}
diff --git a/perllib/FixMyStreet/Geocode/FixaMinGata.pm b/perllib/FixMyStreet/Geocode/FixaMinGata.pm
index 2ea92c422..5c6851011 100644
--- a/perllib/FixMyStreet/Geocode/FixaMinGata.pm
+++ b/perllib/FixMyStreet/Geocode/FixaMinGata.pm
@@ -14,7 +14,6 @@ package FixMyStreet::Geocode::FixaMinGata;
use warnings;
use strict;
-use Data::Dumper;
use Digest::MD5 qw(md5_hex);
use Encode;
@@ -23,7 +22,7 @@ use File::Path ();
use LWP::Simple qw($ua);
use Memcached;
use XML::Simple;
-use mySociety::Locale;
+use Utils;
my $osmapibase = "http://www.openstreetmap.org/api/";
my $nominatimbase = "http://nominatim.openstreetmap.org/";
@@ -45,8 +44,8 @@ sub string {
my %query_params = (
q => $s,
format => 'json',
- addressdetails => 1,
- limit => 20,
+ addressdetails => 1,
+ limit => 20,
#'accept-language' => '',
email => 'info' . chr(64) . 'morus.se',
);
@@ -77,32 +76,25 @@ sub string {
my ( %locations, $error, @valid_locations, $latitude, $longitude );
foreach (@$js) {
- # These co-ordinates are output as query parameters in a URL, make sure they have a "."
- next if $_->{class} eq "boundary";
-
- my @s = split(/,/, $_->{display_name});
-
- my $address = join(",", @s[0,1,2]);
-
+ next if $_->{class} eq "boundary";
+ my @s = split(/,/, $_->{display_name});
+ my $address = join(",", @s[0,1,2]);
$locations{$address} = [$_->{lat}, $_->{lon}];
}
- my ($key) = keys %locations;
-
- return { latitude => $locations{$key}[0], longitude => $locations{$key}[1] } if scalar keys %locations == 1;
- return { error => _('Sorry, we could not find that location.') } if scalar keys %locations == 0;
-
- foreach $key (keys %locations) {
- ( $latitude, $longitude ) = ($locations{$key}[0], $locations{$key}[1]);
- mySociety::Locale::in_gb_locale {
- push (@$error, {
- address => $key,
- latitude => sprintf('%0.6f', $latitude),
- longitude => sprintf('%0.6f', $longitude)
- });
- };
+ foreach my $key (keys %locations) {
+ ( $latitude, $longitude ) =
+ map { Utils::truncate_coordinate($_) }
+ ($locations{$key}[0], $locations{$key}[1]);
+ push (@$error, {
+ address => $key,
+ latitude => $latitude,
+ longitude => $longitude
+ });
+ push (@valid_locations, $_);
}
+ return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1;
return { error => $error };
}
diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm
index 11ff8ef80..d83920a81 100644
--- a/perllib/FixMyStreet/Geocode/Google.pm
+++ b/perllib/FixMyStreet/Geocode/Google.pm
@@ -12,7 +12,7 @@ use File::Slurp;
use File::Path ();
use LWP::Simple;
use Digest::MD5 qw(md5_hex);
-use mySociety::Locale;
+use Utils;
# string STRING CONTEXT
# Looks up on Google Maps API, and caches, a user-inputted location.
@@ -78,15 +78,14 @@ sub string {
next unless $_->{AddressDetails}->{Accuracy} >= 4;
my $address = $_->{address};
next unless $c->cobrand->geocoded_string_check( $address );
- ( $longitude, $latitude ) = @{ $_->{Point}->{coordinates} };
- # These co-ordinates are output as query parameters in a URL, make sure they have a "."
- mySociety::Locale::in_gb_locale {
- push (@$error, {
- address => $address,
- latitude => sprintf('%0.6f', $latitude),
- longitude => sprintf('%0.6f', $longitude)
- });
- };
+ ( $longitude, $latitude ) =
+ map { Utils::truncate_coordinate($_) }
+ @{ $_->{Point}->{coordinates} };
+ push (@$error, {
+ address => $address,
+ latitude => $latitude,
+ longitude => $longitude
+ });
push (@valid_locations, $_);
}
return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1;
diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm
index 919940f78..082d8fbc1 100644
--- a/perllib/FixMyStreet/Geocode/OSM.pm
+++ b/perllib/FixMyStreet/Geocode/OSM.pm
@@ -16,7 +16,7 @@ use File::Path ();
use LWP::Simple qw($ua);
use Memcached;
use XML::Simple;
-use mySociety::Locale;
+use Utils;
my $osmapibase = "http://www.openstreetmap.org/api/";
my $nominatimbase = "http://nominatim.openstreetmap.org/";
@@ -68,15 +68,14 @@ sub string {
my ( $error, @valid_locations, $latitude, $longitude );
foreach (@$js) {
- # These co-ordinates are output as query parameters in a URL, make sure they have a "."
- ( $latitude, $longitude ) = ( $_->{lat}, $_->{lon} );
- mySociety::Locale::in_gb_locale {
- push (@$error, {
- address => $_->{display_name},
- latitude => sprintf('%0.6f', $latitude),
- longitude => sprintf('%0.6f', $longitude)
- });
- };
+ ( $latitude, $longitude ) =
+ map { Utils::truncate_coordinate($_) }
+ ( $_->{lat}, $_->{lon} );
+ push (@$error, {
+ address => $_->{display_name},
+ latitude => $latitude,
+ longitude => $longitude
+ });
push (@valid_locations, $_);
}
diff --git a/perllib/FixMyStreet/Geocode/Zurich.pm b/perllib/FixMyStreet/Geocode/Zurich.pm
index 1f0b4fc16..7de2cc272 100644
--- a/perllib/FixMyStreet/Geocode/Zurich.pm
+++ b/perllib/FixMyStreet/Geocode/Zurich.pm
@@ -15,7 +15,7 @@ use Digest::MD5 qw(md5_hex);
use File::Path ();
use Geo::Coordinates::CH1903;
use Storable;
-use mySociety::Locale;
+use Utils;
my ($soap, $method, $security);
@@ -92,14 +92,14 @@ sub string {
my ( $error, @valid_locations, $latitude, $longitude );
foreach (@$results) {
- ($latitude, $longitude) = Geo::Coordinates::CH1903::to_latlon($_->{easting}, $_->{northing});
- mySociety::Locale::in_gb_locale {
- push (@$error, {
- address => $_->{text},
- latitude => sprintf('%0.6f', $latitude),
- longitude => sprintf('%0.6f', $longitude)
- });
- };
+ ($latitude, $longitude) =
+ map { Utils::truncate_coordinate($_) }
+ Geo::Coordinates::CH1903::to_latlon($_->{easting}, $_->{northing});
+ push (@$error, {
+ address => $_->{text},
+ latitude => $latitude,
+ longitude => $longitude
+ });
push (@valid_locations, $_);
last if lc($_->{text}) eq lc($s);
}