And*_*sov 32 javascript html5 android google-chrome geolocation
这段代码:
navigator.geolocation.getCurrentPosition(
function(position) {
alert(position.coords.latitude, position.coords.longitude);
},
function(error){
alert(error.message);
}, {
enableHighAccuracy: true
,timeout : 5000
}
);
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/FcRpM/在我的笔记本电脑上使用谷歌Chrome浏览器,但在移动HTC one S(安卓4.1,GPS关闭,通过移动网络和启用wifi的位置),通过WiFi连接到互联网.
其他Android应用程序找到我正确.
Adr*_*ian 17
你可以试试这个.它似乎适用于我的设备(三星Galaxy Nexus在Wi-Fi上运行Chrome 27.0.1453.90(没有数据连接,没有GPS))
Run Code Online (Sandbox Code Playgroud)navigator.geolocation.getCurrentPosition( function(position) { alert("Lat: " + position.coords.latitude + "\nLon: " + position.coords.longitude); }, function(error){ alert(error.message); }, { enableHighAccuracy: true ,timeout : 5000 } );
问题是警报只接受字符串(以原始形式)但是你传递了2个双打.例如,将警报框修改为alert('Hey', 'Hello');仅输出Hey.更改,为+,您将获得连接的字符串HeyHello.您不能在其中使用+符号,alert因为方程式将首先执行然后显示.
希望这说清楚.
有一个替代方法:watchPosition调用,并在清除watchID之前等待5秒钟.代码如下;
var options = { enableHighAccuracy: true, maximumAge: 100, timeout: 60000 };
if( navigator.geolocation) {
var watchID = navigator.geolocation.watchPosition( gotPos, gotErr, options );
var timeout = setTimeout( function() { navigator.geolocation.clearWatch( watchID ); }, 5000 );
} else {
gotErr();
}
Run Code Online (Sandbox Code Playgroud)
我没有玩过"选项"值或此刻的超时延迟,但上面的代码在我尝试的每个平台上都带回了准确的定位信息.
刚完成测试一堆移动设备和Javascript Geolocation.我使用了Google的示例代码,以确保问题不在我自己的代码中.
Chrome for Android 4.4似乎不适用于仅限GPS的定位服务,2.3版本的浏览器也不适用.他们都需要"高精度" - 使用无线和3G/4G网络.
有趣的是,Firefox for Android可以毫无问题地使用GPS.只有现有的Android浏览器(Chrome + Mobile Safari)才能使用仅限GPS的位置设置.
其余的团伙 - 带有GPS,Windows和Linux(都带有ADSL)的Lumia WP8可以与任何位置设置完美配合.
| 归档时间: |
|
| 查看次数: |
52509 次 |
| 最近记录: |