最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - navigator.geolocation giving wrong results - Stack Overflow

programmeradmin0浏览0评论

I'm working on a webapp that can use geolocation to do cool things, and right now I'm just lost because navigator.geolocation is giving me wrong results.

My debug code :

navigator.geolocation.getCurrentPosition(
    function(p) {console.log(p.coords)},
    function(p) {console.log('bug')},
    {enableHighAccuracy: true}
)

the result :

Coordinates {speed: null, heading: null, altitudeAccuracy: null, accuracy:  140843, altitude: null…}
    accuracy: 140843
    altitude: null
    altitudeAccuracy: null
    heading: null
    latitude: 46.1902742
    longitude: 6.1464840999999995
    ...

The problem is : The coordinates are plain wrong. I'm not in Geneva at all. I'm in another part of Switzerland.

And this problem happens on my puter, on my friend puter, on linux puters, on windows puters, on mac puters.

What is the problem ? Is navigator.geolocation obselet ? not working in switzerland ? I'm just missing something ?

I'm working on a webapp that can use geolocation to do cool things, and right now I'm just lost because navigator.geolocation is giving me wrong results.

My debug code :

navigator.geolocation.getCurrentPosition(
    function(p) {console.log(p.coords)},
    function(p) {console.log('bug')},
    {enableHighAccuracy: true}
)

the result :

Coordinates {speed: null, heading: null, altitudeAccuracy: null, accuracy:  140843, altitude: null…}
    accuracy: 140843
    altitude: null
    altitudeAccuracy: null
    heading: null
    latitude: 46.1902742
    longitude: 6.1464840999999995
    ...

The problem is : The coordinates are plain wrong. I'm not in Geneva at all. I'm in another part of Switzerland.

And this problem happens on my puter, on my friend puter, on linux puters, on windows puters, on mac puters.

What is the problem ? Is navigator.geolocation obselet ? not working in switzerland ? I'm just missing something ?

Share Improve this question edited Dec 2, 2021 at 23:47 Samvel Aleqsanyan 2,9744 gold badges21 silver badges28 bronze badges asked Feb 20, 2015 at 8:41 Spoutnik16Spoutnik16 8641 gold badge12 silver badges19 bronze badges 8
  • are you using same internet connection always? Is a VPN? Lan/VPN connections can be redirected through other physical places. – Jordi Castilla Commented Feb 20, 2015 at 8:47
  • it is a lan connection, same corporate network. But I've set no VPN up (and I'm managing that network). – Spoutnik16 Commented Feb 20, 2015 at 8:53
  • 140km is a really high value for accuracy... Have you tried enabling enableHighAccuracy in the options? .getCurrentPosition(successCallback, errorCallback, options), PositionOptions – Andreas Commented Feb 20, 2015 at 9:04
  • yeah, same results (edited the main to add it) – Spoutnik16 Commented Feb 20, 2015 at 9:09
  • What if you try another site that tells you your location? I mean, same network, other website? Such as html5demos./geo – Jonas Grumann Commented Feb 20, 2015 at 9:12
 |  Show 3 more ments

1 Answer 1

Reset to default 4

Do you have GPS-dongle connected to PC ? Or geolocation source is any wrong IP-geo tool or Wifi/Cell. You can't get your exact physical coordinates by IP-address. If you use WiFi network accuracy can be 5-50 meters, but you are using LAN. Geolocation by IP is very very inaccurate, it's normaly to get wrong city or country.

发布评论

评论列表(0)

  1. 暂无评论