我正在使用以下代码来获取使用watchPosition的用户位置。我还想定义失败参数的代码并将选项传递给watchPosition
,但我不确定代码应该放在哪里。使用具有箭头功能的watchPosition
if (navigator.geolocation) {
//Success callback defined, but where shouls fail & options go?
var positionTimer = navigator.geolocation.watchPosition((position) => {
var crd = position.coords;
console.log("Updated user loc...");
console.log(crd.latitude + " : " + crd.longitude);
this.myLatitude = crd.latitude;
this.myLongitude = crd.longitude;
this.updateUserLocation();
},
console.warn("Error getting user location"),
this.options);
}
else {
alert("Geolocation not supported in your browser!");
}
这是一个在您发布的文档。第一个参数是成功回调,第二个参数是错误回调,第三个参数是具有选项的对象。它包括我知道的一个示例 – Gerardo
,但我不知道使用箭头函数时回调的位置。 – TomSelleck
'watchPosition((success)=> {...},(error)=> {...},options);' – Gerardo