Created
April 19, 2012 17:00
-
-
Save dongilbert/2422306 to your computer and use it in GitHub Desktop.
Geolocate an Address Using Google Maps via PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// URL Encode the address | |
$address = urlencode($data['storelocator']['address']); | |
// Get the JSON response from google. You can also get XML by changing geocode/json to geocode/xml | |
$geo = file_get_contents('http://maps.google.com/maps/api/geocode/json?sensor=false&address='.$address); | |
// Decode the results into an Object | |
$result = json_decode($geo); | |
// If it came back ok, retrieve the latitude and longitude from the results. | |
if($result->status === 'OK') | |
{ | |
$lat = $result->results[0]->geometry->location->lat; | |
$lng = $result->results[0]->geometry->location->lng; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment