Created
April 19, 2017 13:28
-
-
Save guiliredu/a2ae4a9f18435953a0e3c7912cf4e7d7 to your computer and use it in GitHub Desktop.
Google Maps Geocode query in backend with 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 | |
function getLatLongByAddress($address){ | |
$prepAddr = str_replace(' ','+',$address); | |
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false'); | |
$output = json_decode($geocode); | |
$return['latitude'] = $output->results[0]->geometry->location->lat; | |
$return['longitude'] = $output->results[0]->geometry->location->lng; | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment