Created
June 13, 2013 22:06
-
-
Save stefanbc/5777799 to your computer and use it in GitHub Desktop.
Get coordinates for a specified address
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 | |
// Get coordinates for a specified address | |
function getCoordinates($address){ | |
$address = str_replace(" ", "+", $address); // replcae all the white space with "+" sign to match with google search pattern | |
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$address"; | |
$response = file_get_contents($url); | |
$json = json_decode($response,TRUE); //generate array object from the response from the web | |
return ($json['results'][0]['geometry']['location']['lng'].",".$json['results'][0]['geometry']['location']['lat']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment