Skip to content

Instantly share code, notes, and snippets.

@mokemokechicken
Created September 3, 2012 09:57
Show Gist options
  • Save mokemokechicken/3608205 to your computer and use it in GitHub Desktop.
Save mokemokechicken/3608205 to your computer and use it in GitHub Desktop.
MVC4 Current Location
$(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