HTML5 geolocation is not accurate

偶尔善良 提交于 2020-06-16 08:36:48

问题


I was using the following code to get my current location. But the longitude and latitude generated was not at all accurate. It was showing a location about 700 Kms away from my location. How can I make it accurate?

<script>
    var x = document.getElementById("demo");
    function getLocation() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        } else {
            x.innerHTML = "Geolocation is not supported by this browser.";
        }
    }
    function showPosition(position) {
        x.innerHTML = "Latitude: " + position.coords.latitude + 
        "<br>Longitude: " + position.coords.longitude; 
    }
    </script>

回答1:


Or you could try a different geocoding provider.

There are lots to choose from:

  • https://smartystreets.com
  • http://geocoder.us
  • http://geoservices.tamu.edu/Services/Geocode/

Disclaimer: I'm a developer at SmartyStreets.




回答2:


Probably you are not using GPS. If you aren't, then navigator.geolocation.getCurrentPosition returns a position based on your ISP



来源:https://stackoverflow.com/questions/30048125/html5-geolocation-is-not-accurate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!