0

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?

Manse
  • 37,765
  • 10
  • 83
  • 108
Ozkan
  • 3,880
  • 9
  • 47
  • 78

2 Answers2

5

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):

  • Firefox 3.5+
  • Chrome 5.0+
  • Safari 5.0+
  • Opera 10.60+
  • Internet Explorer 9.0+

API Spec here

Manse
  • 37,765
  • 10
  • 83
  • 108
5
  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 


}

you can find details here

Warning:This will popup a permission dialog in browsers that will look something like this (Safari): enter image description here

Raab
  • 34,778
  • 4
  • 50
  • 65