Compare View
Commits (2)
Showing
1 changed file
 
Show diff stats
map.php
| 1 | <?php | 1 | <?php | 
| 2 | print_r(getLatLng('台灣新北市')); | 2 | print_r(getLatLng('台灣新北市')); | 
| 3 | function getLatLng($address){ | 3 | function getLatLng($address){ | 
| 4 | 4 | ||
| 5 | // url encode the address | 5 | // url encode the address | 
| 6 | $address = urlencode($address); | 6 | $address = urlencode($address); | 
| 7 | 7 | ||
| 8 | // google map geocode api url | 8 | // google map geocode api url | 
| 9 | $url = "http://maps.google.com/maps/api/geocode/json?address={$address}"; | 9 | $url = "http://maps.google.com/maps/api/geocode/json?address={$address}"; | 
| 10 | $curl = curl_init() ; | 10 | $curl = curl_init() ; | 
| 11 | curl_setopt($curl , | 11 | curl_setopt($curl , | 
| 12 | CURLOPT_URL , | 12 | CURLOPT_URL , | 
| 13 | "$url") ; | 13 | "$url") ; | 
| 14 | 14 | ||
| 15 | curl_setopt($curl , CURLOPT_RETURNTRANSFER , 1) ; | 15 | curl_setopt($curl , CURLOPT_RETURNTRANSFER , 1) ; | 
| 16 | 16 | ||
| 17 | $info = curl_exec($curl) ; | 17 | $info = curl_exec($curl) ; | 
| 18 | 18 | ||
| 19 | curl_close($curl) ; | 19 | curl_close($curl) ; | 
| 20 | 20 | ||
| 21 | $a = json_decode($info); | 21 | $a = json_decode($info); | 
| 22 | 22 | ||
| 23 | $latlng = array($a->results['0']->geometry->bounds->southwest->lat,$a->results['0']->geometry->bounds->southwest->lng); | 23 | $latlng = array($a->results['0']->geometry->bounds->southwest->lat,$a->results['0']->geometry->bounds->southwest->lng); | 
| 24 | 24 | ||
| 25 | return $latlng; | 25 | return $latlng; | 
| 26 | 26 | ||
| 27 | } | 27 | } | 
| 28 | ?> | ||
| 29 | aaa | 28 | ?> |