Commit c75c321b18ce80a639924ae1f843e8428cc8c38e
1 parent
dbaadcdd8b
Exists in
master
a
Showing
1 changed file
with
2 additions
and
1 deletions
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 | ?> | ||
| 28 | ?> |