navigator.geolocation.getCurrentPosition doesn#39;t work on android google chrome(navigator.geolocation.getCurrentPosition 在 android google chrome 上不起作用)
问题描述
这段代码:
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 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:navigator.geolocation.getCurrentPosition 在 android google c


基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01