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
// http://jonrohan.me/guide/javascript/geolocation-api/ | |
function getLocation() { | |
2 if(navigator.geolocation) { | |
3 navigator.geolocation.getCurrentPosition(foundLocation, noLocation); | |
4 } else { | |
5 noLocation(); | |
6 } | |
7 } | |
8 function foundLocation(position) { | |
9 var lat = position.coords.latitude; | |
10 var long = position.coords.longitude; | |
11 $("#current-location").replaceWith('<a id="current-location" href="http://maps.google.com/?q=' + lat + ',' + long + '" target="_blank">' + lat + ', ' + long + '</a>'); | |
12 } | |
13 function noLocation() { | |
14 $("#current-location").text('Could not find location'); | |
15 } | |
16 $("#get-location").click(getLocation); |
No comments:
Post a Comment