【发布时间】:2017-02-04 17:32:03
【问题描述】:
我有这段代码可以使用 html5 地理位置
this.getCurrentLocation = function(callback) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (pos) {
callback({
'lat' : pos.coords.latitude,
'lng' : pos.coords.longitude
});
}, function (error) {
switch(error.code) {
case error.PERMISSION_DENIED:
alert("Could not get your location. User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Could not get your location. Location information is unavailable.");
break;
case error.TIMEOUT:
alert("Could not get your location. The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("Could not get your location. An unknown error occurred.");
break;
default:
alert("Could not get your location. An unknown error occurred.");
}
callback(null);
}, {
maximumAge: 500000,
enableHighAccuracy:true,
timeout: 6000
});
}
};
我正在 Android 手机上的 chrome 浏览器上对其进行测试。但它马上就说用户拒绝了许可。它甚至不问我是否要允许它。我怎样才能得到它来请求许可。我在网站设置中,也应该请求该位置的许可。
如果我在桌面上尝试,它可以工作。
有谁知道怎么回事?
谢谢
【问题讨论】:
标签: javascript android html google-chrome geolocation