html5路段定位,高精度地理定位Html5

Menelaos Bak..

27

您需要一个PositionOptions对象,在API中设置高精度标志.

getCurrentPosition()函数有一个可选的第三个参数,一个PositionOptions对象.您可以在PositionOptions对象中设置三个属性.所有属性都是可选的.您可以设置任何或全部或不设置它们.

POSITIONOPTIONS OBJECT

Property Type Default Notes

--------------------------------------------------------------

enableHighAccuracy Boolean false true might be slower

timeout long (no default) in milliseconds

maximumAge long 0 in milliseconds

所以,它应该像这样工作:

if (navigator.geolocation) {

navigator.geolocation.getCurrentPosition(function(position) {

var latitude = position.coords.latitude;

var longitude = position.coords.longitude;

var accuracy = position.coords.accuracy;

var coords = new google.maps.LatLng(latitude, longitude);

var mapOptions = {

zoom: 15,

center: coords,

mapTypeControl: true,

navigationControlOptions: {

style: google.maps.NavigationControlStyle.SMALL

},

mapTypeId: google.maps.MapTypeId.ROADMAP

};

var capa = document.getElementById("capa");

capa.innerHTML = "latitude: " + latitude + ", longitude: " + ", accuracy: " + accuracy;

map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);

var marker = new google.maps.Marker({

position: coords,

map: map,

title: "ok"

});

},

function error(msg) {alert('Please enable your GPS position feature.');},

{maximumAge:10000, timeout:5000, enableHighAccuracy: true});

} else {

alert("Geolocation API is not supported in your browser.");

}

注意到我添加了以下2个参数来getCurrentPosition调用:

function error(msg){alert('Please enable your GPS position future.');}

无法检索GPS或触发超时时调用此功能.

{maximumAge:10000, timeout:5000, enableHighAccuracy: true});

这些是选项.我们不希望gps数据超过10秒(maximumAge:10000).我们不希望等待超过5秒的响应(timeout:5000),我们希望启用高精度(enableHighAccuracy: true).

@meework您已将enableHighAccuracy设置为false,而不是将其设置为true. (3认同)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值