admin管理员组

文章数量:1357602

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?

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?

Share Improve this question edited Jun 12, 2012 at 9:09 Manse 38.1k11 gold badges86 silver badges111 bronze badges asked Jun 12, 2012 at 8:55 OzkanOzkan 4,1709 gold badges54 silver badges86 bronze badges 1
  • Check this stackoverflow./questions/1535619/… – V4Vendetta Commented Jun 12, 2012 at 8:59
Add a ment  | 

2 Answers 2

Reset to default 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):

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

本文标签: cGet current location of a visitorStack Overflow