<?php $url = "http://maps.google.com/maps/api/geocode/json?address=hyderabad&sensor=false®ion=IN"; $response = file_get_contents($url); $response = json_decode($response, true); //print_r($response); $lat = $response['results'][0]['geometry']['location']['lat']; $long = $response['results'][0]['geometry']['location']['lng']; echo "latitude: " . $lat . " longitude: " . $long; ?>
The print_r command commented out above is a useful way to work out the array structure that you need to drill down to. To get the longitude and latitude values, we need to drill down through 5 levels.
No comments:
Post a Comment