aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Geocode/Bing.pm
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/Bing.pm
parent980d9f82fc76f8d2e73295f3f9fac7b81fdd5660 (diff)
Add address information to description in RSS feeds
Diffstat (limited to 'perllib/FixMyStreet/Geocode/Bing.pm')
-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;
r Unnamed repository; edit this file 'description' to name the repository.MimesBrønn
aboutsummaryrefslogtreecommitdiffstats
path: root/script/rails-post-deploy
blob: 6100bb1d04e710d842b6c833fa5244d577166726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110