我正在測試這個簡單的地理位置代碼,由於某種原因它不適用於iOS設備。我已經在MacOS,Windows,Windows Phone,Android手機等上進行過測試,它的工作原理與所有應用程序一樣。爲什麼這個HTML5地理位置代碼只能在iOS上獲取用戶的位置?
在授予權限後,我總是收到「POSITION_UNAVAILABLE」錯誤。
navigator.geolocation.getCurrentPosition(
function success(position) {
var primary = getUniqueId();
var url = endpointBaseurl +
'?property_code=' + propertyCode +
'&distribService=' + distribService +
'&lat=' + position.coords.latitude +
'&lon=' + position.coords.longitude +
'&distribTarget=' + primary;
//Update the line below to be one of your links.
addMenuItem('Offers', url);
},
function error(err) {
switch (err.code) {
case 1:
alert("You must allow location in order to receive tobacco offers. Please refresh and try again.")
break;
case 2:
alert('POSITION_UNAVAILABLE');
break;
case 3:
alert('Error 3');
break;
default:
alert("Unable to determine your location. Please refresh and try again.");
}
}, options);
我已經在物理設備上以及通過Browserstack進行了測試。該網站使用HTTPS運行。
任何想法爲什麼應該不工作,或者我應該如何去調試?我把頭髮拉過來。
你在StackOverflow上看過[this](http://stackoverflow.com/questions/30998246/html5-geolocation-not-working-all-the-time-on-ios)問題嗎?這可能有一些幫助。 –