Skip to content

Instantly share code, notes, and snippets.

@gauravmehla
Forked from BastinRobin/GetLatLong.js
Created March 27, 2020 08:34
Show Gist options
  • Save gauravmehla/d42f8ef2d4595b70e7615d58e5b6c7d1 to your computer and use it in GitHub Desktop.
Save gauravmehla/d42f8ef2d4595b70e7615d58e5b6c7d1 to your computer and use it in GitHub Desktop.
Get Latitude And Longitude Javascript Function
/* 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