-
-
Save gauravmehla/d42f8ef2d4595b70e7615d58e5b6c7d1 to your computer and use it in GitHub Desktop.
Get Latitude And Longitude Javascript Function
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
/* Get the latitude and longitude from address: | |
Author : Bastin Robins J | |
*/ | |
// Add the link to webpage | |
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> | |
//Function to covert address to Latitude and Longitude | |
var getLocation = function(address) { | |
var geocoder = new google.maps.Geocoder(); | |
geocoder.geocode( { 'address': address}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
var latitude = results[0].geometry.location.lat(); | |
var longitude = results[0].geometry.location.lng(); | |
console.log(latitude, longitude); | |
} | |
}); | |
} | |
//Call the function with address as parameter | |
getLocation('New York'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment