Created
December 12, 2018 07:03
-
-
Save fahidjavid/2dce2b1bc190089f7d7f9221400482e8 to your computer and use it in GitHub Desktop.
Getting the Google Maps Latitude and Longitude of an 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 | |
$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