HTML5 Geolocation Implementation

I have a list of areas and latitudes / longitudes that I ask the user to choose their location when they get to my site. I would like their location to be pre-populated using HTML5 geolocation if possible, but I'm not quite sure if this is the best way to do this. It seems that there are no tutorials on the Internet, at least from what I can find. Has anyone done this? Do you know a good tutorial / resource?

Update

If I have the coordinates of a bunch of cities, how can I use javascript to determine the closest location?

+8
jquery html5 geolocation
source share
4 answers

Try this example:

window.onload = function(){ if(navigator.geolocation) navigator.geolocation.getCurrentPosition(handleGetCurrentPosition, onError); } function handleGetCurrentPosition(location){ location.coords.latitude; location.coords.longitude; } function onError(){...} 

Go here for a larger demo. http://od-eon.com/labs/geolocation/

+9
source share
0
source share
 function load_position() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { l.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { l.innerHTML = "Longitude" + position.coords.latitude + " Longitude " + position.coords.longitude + "</td></tr>" ; } 

Just make a call to load_position () when you want to use the coordinates.

note: l is the identifier of the element in which the data should be placed. Modify it according to your needs.

0
source share

Nettuts has this awesome tutorial, here is the link http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/

-one
source share

All Articles