-
Notifications
You must be signed in to change notification settings - Fork 1
/
Maps.php
39 lines (31 loc) · 910 Bytes
/
Maps.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
<?php
/**
* Obtendo Latitude e Longitude via Google Maps Api V2
* @author Roni - [email protected]
*/
class Maps {
//chave publica de acesso
private static $googleKey = 'SUA_CHAVE_AQUI';
static function loadUrl($url){
$cURL = curl_init($url);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($cURL);
curl_close($cURL);
if($result) {
return $result;
}else{
return false;
}
}
static function getLocal($address) {
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address='. urlencode($address) .'&key='.self::$googleKey;
$result = self::loadUrl($url);
$json = json_decode($result);
if($json->{'status'} == 'OK') {
return $json->{'results'}[0]->{'geometry'}->{'location'};
}else{
return false;
}
}
}