Created
November 15, 2011 12:33
-
-
Save blanchma/1366977 to your computer and use it in GitHub Desktop.
Get latitude and longitude from browser
This file contains 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
// 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