navigator.geolocation.getCurrentPosition不会在Android谷歌浏览器工作 [英] navigator.geolocation.getCurrentPosition doesn't work on android google chrome
问题描述
这code:
navigator.geolocation.getCurrentPosition(
功能(位置){
警报(position.coords.latitude,position.coords.longitude);
},
功能(错误){
警报(返回Error.message);
},{
enableHighAccuracy:真
,超时:5000
}
);
http://jsfiddle.net/FcRpM/ 的谷歌浏览器在我的笔记本电脑工作,但在手机的HTC One S(安卓4.1,GPS关闭,通过移动网络和WiFi位置启用),通过WiFi连接到互联网。
- 在默认浏览器工作正常。
- 在谷歌浏览器,歌剧,Yandex.browser Android的失败,过期超时。
其他Android应用程序找到了我正确的。
您可以试试这个。它似乎工作,我的设备上(运行的Chrome 27.0.1453.90的Wi-Fi(无需数据连接,在没有GPS)三星GALAXY Nexus)
navigator.geolocation.getCurrentPosition( 功能(位置){ 警报(纬度:+ position.coords.latitude +\ nLon:+ position.coords.longitude); }, 功能(错误){ 警报(返回Error.message); },{ enableHighAccuracy:真 ,超时:5000 } );
问题是,警报只需要字符串(在它的原始形式),但是你逝去的2双打。修改例如警告框警报('嗨','你好');
,输出将只有嘿嘿
。更改,
到 +
,你会得到的串联字符串 HeyHello
。你不能使用 +
标志在警告
作为公式将首先执行,然后显示出来。
希望这是清楚。
This code:
navigator.geolocation.getCurrentPosition(
function(position) {
alert(position.coords.latitude, position.coords.longitude);
},
function(error){
alert(error.message);
}, {
enableHighAccuracy: true
,timeout : 5000
}
);
http://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 + "\nLon: " + 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谷歌浏览器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!