-
Notifications
You must be signed in to change notification settings - Fork 2
/
lib_geo_flickr.php
73 lines (48 loc) · 1.27 KB
/
lib_geo_flickr.php
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
<?php
#
# $Id$
#
loadlib("flickr_api");
loadlib("geohash");
#################################################################
function geo_flickr_reverse_geocode($lat, $lon){
$short_lat = (float)sprintf("%.3f", $lat);
$short_lon = (float)sprintf("%.3f", $lon);
$geohash = geohash_encode($short_lat, $short_lon);
$cache_key = "flickr_reversegeocode_{$geohash}";
$cache = cache_get($cache_key);
if ($cache['ok']){
return $cache['data'];
}
$args = array(
'lat' => $short_lat,
'lon' => $short_lon,
);
$rsp = flickr_api_call('flickr.places.findByLatLon', $args);
if (! $rsp['ok']){
return;
}
$loc = $rsp['rsp']['places']['place'][0];
cache_set($cache_key, $loc, 'set locally');
return $loc;
}
#################################################################
function geo_flickr_get_woeid($woeid){
$cache_key = "flickr_woeid_{$woeid}";
$cache = cache_get($cache_key);
if ($cache['ok']){
return $cache['data'];
}
$args = array(
'woe_id' => $woeid,
);
$rsp = flickr_api_call('flickr.places.getInfo', $args);
if (! $rsp['ok']){
return;
}
$loc = $rsp['rsp']['place'];
cache_set($cache_key, $loc, 'set locally');
return $loc;
}
#################################################################
?>