navigator.geolocation.getCurrentPosition 在 android google chrome 上不起作用 [英] navigator.geolocation.getCurrentPosition doesn't work on android google chrome

查看:117
本文介绍了navigator.geolocation.getCurrentPosition 在 android google chrome 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码:

navigator.geolocation.getCurrentPosition(功能(位置){警报(位置.坐标.纬度,位置.坐标.经度);},功能(错误){警报(错误消息);}, {启用高精度:真,超时:5000});

https://jsfiddle.net/FcRpM/ 在我的笔记本电脑上的 Google Chrome 中工作,但在移动 HTC one S(安卓 4.1,GPS 关闭,通过移动网络定位并启用 wifi),通过 WiFi 连接到互联网.

  1. 默认浏览器工作正常.
  2. 适用于 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.

  1. Default browser works fine.
  2. 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 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆