NG-地图 - 火狐navigator.geolocation.getCurrentPosition成功回调不叫
问题描述:
我使用NG-图,我在FFX使用navigator.geolocation.getCurrentPosition来获取用户的当前位置,然而,成功的回调没有按“不像是会被调用。当我添加的回调函数中的断点,这是从来没有打(它在其他浏览器我测试过)。这里是我的代码:NG-地图 - 火狐navigator.geolocation.getCurrentPosition成功回调不叫
var options = {
};
navigator.geolocation.getCurrentPosition(
function (pos) {
var myLatLng = new google.maps.LatLng(parseFloat(pos.coords.latitude), parseFloat(pos.coords.longitude));
map.setCenter(myLatLng);
},
function (error) { return false; },
options);
我已经试过什么:
- 检查是否错误回调被调用(它永远不会是,我看不到任何错误)
- 加入短(例如5000ms)超时
- 设置enableHighAccuracy在选项中显式为false
- 显式指定'success'和'error'函数并调用它们,而不是添加函数'inline' (不,这应该使任何区别,也没有,它没有!)
- 使用,而不是getCurrentPosition navigator.geolocation.watchPosition
- 我使用地图的NG-MAP角指令,和我已经试过从显示的当前位置,我的自定义标记删除“位置”,以尽量确保没有什么干扰,或拦截回调。
任何新的想法或任何东西,我可以尝试的建议都非常欢迎!
答
我发现设置:
position="current-location"
上,我使用来显示当前位置与NG-地图实际上确实呼叫navigator.geolocation.getCurrentPosition
和我自己的呼叫getCurrentPosition
被干扰<custom-marker>
。我现在用下面的位置在我<custom-marker>
:
position="{{mapsCtrl.userLat + ',' + mapsCtrl.userLng}}"
...,我把它像这样:
navigator.geolocation.getCurrentPosition(
function (pos) {
var myLatLng = new google.maps.LatLng(parseFloat(pos.coords.latitude), parseFloat(pos.coords.longitude));
this.setCurrentLocationMarker(myLatLng);
map.setCenter(myLatLng);
},
function (error) { return false; });
setCurrentLocationMarker(latLng) {
this.userLat = latLng.lat();
this.userLng = latLng.lng();
this.$scope.$apply();
}