aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-08-29 16:38:23 +0100
committerStruan Donald <struan@exo.org.uk>2011-08-29 16:38:23 +0100
commitc5de0e84387943901e89f8d327d4e97048e7c20c (patch)
treeb1f8bc3644d92f51dc2d292074be418c850228ff /perllib/FixMyStreet/Geocode
parent980d9f82fc76f8d2e73295f3f9fac7b81fdd5660 (diff)
Add address information to description in RSS feeds
Diffstat (limited to 'perllib/FixMyStreet/Geocode')
-rw-r--r--perllib/FixMyStreet/Geocode/Bing.pm32
1 files changed, 32 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm
index 90d7f98bd..4e12a7a7f 100644
--- a/perllib/FixMyStreet/Geocode/Bing.pm
+++ b/perllib/FixMyStreet/Geocode/Bing.pm
@@ -64,4 +64,36 @@ sub string {
return { error => $error };
}
+sub reverse {
+ my ( $latitude, $longitude, $cache ) = @_;
+
+ # Get nearest road-type thing from Bing
+ my $key = mySociety::Config::get('BING_MAPS_API_KEY', '');
+ if ($key) {
+ my $url = "http://dev.virtualearth.net/REST/v1/Locations/$latitude,$longitude?c=en-GB&key=$key";
+ my $j;
+ if ( $cache ) {
+ my $cache_dir = FixMyStreet->config('GEO_CACHE') . 'bing/';
+ my $cache_file = $cache_dir . md5_hex($url);
+
+ if (-s $cache_file) {
+ $j = File::Slurp::read_file($cache_file);
+ } else {
+ $j = LWP::Simple::get($url);
+ File::Path::mkpath($cache_dir);
+ File::Slurp::write_file($cache_file, $j) if $j;
+ }
+ } else {
+ $j = LWP::Simple::get($url);
+ }
+
+ if ($j) {
+ $j = JSON->new->utf8->allow_nonref->decode($j);
+ return $j;
+ }
+ }
+
+ return undef;
+}
+
1;