問題描述
這段代碼:
navigator.geolocation.getCurrentPosition(功能(位置){警報(位置.坐標.緯度,位置.坐標.經度);},功能(錯誤){警報(錯誤消息);}, {啟用高精度:真,超時:5000});
https://jsfiddle.net/FcRpM/ 在我的筆記本電腦上的 Google Chrome 中工作,但在移動 HTC one S(安卓 4.1,GPS 關閉,通過移動網絡定位并啟用 wifi),通過 WiFi 連接到互聯網.
- 默認瀏覽器工作正常.
- 適用于 Android 的 Google Chrome、Opera、Yandex.browser 失敗并顯示超時已過期".
其他 android 應用程序正確定位我.
你可以試試這個.它似乎可以在我的設備上運行(三星 Galaxy Nexus 在 Wi-Fi 上運行 Chrome 27.0.1453.90(無數據連接,無 GPS))
<塊引用>navigator.geolocation.getCurrentPosition(功能(位置){alert("Lat: " + position.coords.latitude + "
Lon: " + position.coords.longitude);},功能(錯誤){警報(錯誤消息);}, {啟用高精度:真,超時:5000});
問題是警報只接受字符串(以其原始形式),但是您傳遞了 2 個雙打.例如,將警告框修改為 alert('Hey', 'Hello');
,輸出將僅為 Hey
.將 ,
更改為 +
,您將獲得串聯的字符串 HeyHello
.您不能在 alert
內使用 +
符號,因為等式將首先執行然后顯示.
希望這能說明問題.
This code:
navigator.geolocation.getCurrentPosition(
function(position) {
alert(position.coords.latitude, position.coords.longitude);
},
function(error){
alert(error.message);
}, {
enableHighAccuracy: true
,timeout : 5000
}
);
https://jsfiddle.net/FcRpM/ works in Google Chrome at my laptop, but on mobile HTC one S (android 4.1, GPS off, location via mobile networks and wifi enabled), connected to internet via WiFi.
- Default browser works fine.
- Google Chrome, Opera, Yandex.browser for android fails with "Timeout expired".
other android apps locates me correct.
You can try this. It seems to work on my device (Samsung Galaxy Nexus running Chrome 27.0.1453.90 on Wi-Fi (no data connection, no GPS on))
navigator.geolocation.getCurrentPosition( function(position) { alert("Lat: " + position.coords.latitude + " Lon: " + position.coords.longitude); }, function(error){ alert(error.message); }, { enableHighAccuracy: true ,timeout : 5000 } );
The problem is that alert only takes strings (in it's original form) however you are passing 2 doubles. Modify the alert box for example to alert('Hey', 'Hello');
and the output will be only Hey
. Change the ,
to +
and you'll get the concatenated strings HeyHello
. You can't use a +
sign inside the alert
as the equation will be first executed and then displayed.
Hope this makes it clear.
這篇關于navigator.geolocation.getCurrentPosition 在 android google chrome 上不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!