Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get latitude and longitude from browser
// if the browser supports the w3c geo api
if(navigator.geolocation){
// get the current position
navigator.geolocation.getCurrentPosition(
// if this was successful, get the latitude and longitude
function(position){
var lat = position.coords.latitude;
var lon = position.coords.longitude;
},
// if there was an error
function(error){
alert('ouch');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment