Created
September 3, 2012 09:57
-
-
Save mokemokechicken/3608205 to your computer and use it in GitHub Desktop.
MVC4 Current Location
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
$(function () { | |
var watchID; | |
$("#watch").click(function () { | |
if (Modernizr.geolocation) { | |
var nav = window.navigator; | |
if (nav != null) { | |
var geoloc = nav.geolocation; | |
watchID = geoloc.watchPosition(showMap, handle_errors); | |
} | |
} | |
else { $("#message").text("You'll need to enter your address manually."); } | |
}); | |
}); | |
function handle_errors(error) { | |
switch (error.code) { | |
case error.PERMISSION_DENIED: | |
alert("User did not share geolocation data"); | |
break; | |
case error.POSITION_UNAVAILABLE: | |
alert("Could not detect current position"); | |
break; | |
case error.TIMEOUT: | |
alert("Time out"); | |
break; | |
default: | |
alert("Unknown error"); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment