Skip to content

Instantly share code, notes, and snippets.

@alfredfrancis
Last active April 26, 2016 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredfrancis/ac5bc0fa6ec88bf6a03b172c0404b248 to your computer and use it in GitHub Desktop.
Save alfredfrancis/ac5bc0fa6ec88bf6a03b172c0404b248 to your computer and use it in GitHub Desktop.
<?php
function getCoordinates($location)
{
$address = str_replace(" ", "+", $location);
$url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address=$location";
$response = file_get_contents($url);
$json = json_decode($response,TRUE);
return ($json['results'][0]['geometry']['location']['lat'].",".$json['results'][0]['geometry']['location']['lng']);
}
echo getCoordinates('gandhinagar,jaipur');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment