Skip to content

Instantly share code, notes, and snippets.

@sachintaware
Forked from BastinRobin/GetLatLong.js
Created September 25, 2015 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachintaware/b54a4ad3dd5afed1ce39 to your computer and use it in GitHub Desktop.
Save sachintaware/b54a4ad3dd5afed1ce39 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