Skip to content

Instantly share code, notes, and snippets.

@fahidjavid
Created December 12, 2018 07:03
Show Gist options
  • Save fahidjavid/2dce2b1bc190089f7d7f9221400482e8 to your computer and use it in GitHub Desktop.
Save fahidjavid/2dce2b1bc190089f7d7f9221400482e8 to your computer and use it in GitHub Desktop.
Getting the Google Maps Latitude and Longitude of an Address
<?php
$address = 'Visalia, CA, USA'; // any address you want latitude and longitude of
$address_encoded = urlencode($address);
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=". $address_encoded ."&key=YOUR_API_KEY";
$result = file_get_contents($url);
$geocode = json_decode($result, true); // returing json of all information about given address
$location = $geocode['results'][0]['geometry']['location'];
$location_lat = $location['lat'];
$location_lng = $location['lng'];
// google maps documentaiotn referrence https://developers.google.com/maps/documentation/geocoding/start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment