Reputation: 4170
I already found functionality that can give a users country or state using his or her IP address. But what I actually need is the exact location.
Like you can see on this link, it is possible to get the very specific current location of a user.
How is this possible with ASP.NET C#, Javascript or jQuery?
Upvotes: 0
Views: 3857
Reputation: 35582
navigator.geolocation.getCurrentPosition(
onSuccess,
onError, {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 120000
});
function onSuccess(position) {
//the following are available to use
//position.coords.latitude
//position.coords.longitude
// position.coords.altitude
// position.coords.accuracy
// position.coords.altitudeAccuracy
// position.coords.heading
// position.coords.speed
}
Warning:This will popup a permission dialog in browsers that will look something like this (Safari):
Upvotes: 5
Reputation: 38147
You could use the Geolocation API in JavaScript ... to get the current position use this :
navigator.geolocation.getCurrentPosition(function(position) {
do_something(position.coords.latitude, position.coords.longitude);
});
do_something()
could be to update a map or just show the current longitude and latitude. Nice simple example here
Browser support (Source):
Upvotes: 5