How to find my distance to a known location in JavaScript
Using JavaScript in the browser, how can I determine the distance from my current location to another location for which I have the latitude and longitude? Frank van Puffelen If your code runs in a browser, you can use the HTML5 geolocation API: window.navigator.geolocation.getCurrentPosition(function(pos) { console.log(pos); var lat = pos.coords.latitude; var lon = pos.coords.longitude; }) Once you know the current position and the position of your "target", you can calculate the distance between them in the way documented in this question: Calculate distance between two latitude-longitude