使用html5地理位置的网页不如Google Map准确吗?

时间:2018-08-18 10:58:20

标签: html5 google-maps geolocation

使用便携式计算机上的网络浏览器Chrome,我打开了一个本地html网页以获取当前位置。返回的位置(1.3238272,103.8606336)在我的实际位置附近。相似,[1]之类的网站(1.3238272 103.8606336)[2](1.32383,103.86063)均返回不准确的结果。

但是,它使用google map返回了(1.287264,103.831497)一个非常准确的位置。谷歌地图是否使用其他方法/技术来获取位置?

<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>

    <script>
        var g_lat = 0;
        var g_lng = 0;
        var map, infoWindow;
        function initMap() {
            navigator.geolocation.getCurrentPosition(updatePosition);
            map = new google.maps.Map(document.getElementById('map'), {
                center: {lat: g_lat, lng: g_lng},
                zoom: 8
            });
            infoWindow = new google.maps.InfoWindow;
        }
        function updatePosition(position) {
            var pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
            };

            infoWindow.setPosition(pos);
            infoWindow.setContent('Location found.');
            infoWindow.open(map);
            map.setCenter(pos);
        }

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
    async defer></script>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

用户登录时使用Google Map的错误,这将产生更好的定位结果。如果不登录,则得到的位置与地理位置相同。