Skip to content

Instantly share code, notes, and snippets.

@jdrew1303
Forked from BastinRobin/GetLatLong.js
Last active January 20, 2016 19:11
Show Gist options
  • Save jdrew1303/0e81a4a3ed18ab41d9ea to your computer and use it in GitHub Desktop.
Save jdrew1303/0e81a4a3ed18ab41d9ea 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