提高 GPS 精度(在 HTML5 地理定位中)

3
如何在此代码中增加GPS的准确性?
var map;

function initialize() {
  var mapOptions = {
    zoom: 18
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  // Try HTML5 geolocation
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = new google.maps.LatLng(position.coords.latitude,
                                       position.coords.longitude);


      var marker = new google.maps.Marker({
          position: pos,
          map: map,
          title: 'You Are Here'

      });

      map.setCenter(pos);
    }, function() {
      handleNoGeolocation(true);
    });
  } else {
    // Browser doesn't support Geolocation
    handleNoGeolocation(false);
  }

}

有一种方法可以这样做吗?我知道可以通过EnableHighAccuracy:true实现,但我不知道在哪里输入此命令。有人有解决方案吗?

1个回答

6
引用自地理位置 API 规范的表单如下:
interface Geolocation { 
       void getCurrentPosition(PositionCallback successCallback,
                               optional PositionErrorCallback errorCallback,
                               optional PositionOptions options)
       [...]
  }

[...]

The enableHighAccuracy attribute provides a hint that the application would like to receive the best possible results.

这意味着你可以将其作为最后一个参数传递给对象,例如(最简示例):
navigator.geolocation.getCurrentPosition(
    function(position) { console.log(position); }, // Success callback
    function() {}, // Error callback
    {enableHighAccuracy: true} // Position Options
);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接