Skip to content

Instantly share code, notes, and snippets.

@guiliredu
Created April 19, 2017 13:28
Show Gist options
  • Save guiliredu/a2ae4a9f18435953a0e3c7912cf4e7d7 to your computer and use it in GitHub Desktop.
Save guiliredu/a2ae4a9f18435953a0e3c7912cf4e7d7 to your computer and use it in GitHub Desktop.
Google Maps Geocode query in backend with PHP
<?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