-
Notifications
You must be signed in to change notification settings - Fork 18
/
geo_api.php
55 lines (46 loc) · 1.44 KB
/
geo_api.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
<?php
function get_timezone($lat,$lon, $time = false) {
if (!$time) $time = time();
$url = 'https://maps.googleapis.com/maps/api/timezone/json?location='.$lat.','.$lon.'×tamp='.$time.'&key='.TZ_API_KEY;
echo $url;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
debug_log($url,'T>');
$json_response = curl_exec($curl);
debug_log($json_response,'<T');
$response = json_decode($json_response,true);
if ($response['status']=='OK') {
return $response['timeZoneId'];
} else {
debug_log($json_response,'!');
return false;
}
}
function get_address($lat,$lon) {
$url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='.$lat.','.$lon.'&key='.TZ_API_KEY;
echo $url;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
debug_log($url,'G>');
$json_response = curl_exec($curl);
debug_log($json_response,'<G');
$response = json_decode($json_response,true);
if ($response['status']=='OK') {
$result = '';
$type = '';
foreach ($response['results'] as $v) {
if ($v['formatted_address'] && !$result) {
$result = $v['formatted_address'];
$type = $v['geometry']['location_type'];
}
if ($type=='ROOFTOP') return $result;
}
//return $response['rawOffset'];
return $result;
} else {
debug_log($json_response,'!');
return false;
}
}