这段代码:
navigator.geolocation.getCurrentPosition(功能(位置){警报(位置.坐标.纬度,位置.坐标.经度);},功能(错误){警报(错误消息);}, {启用高精度:真,超时:5000});https://jsfiddle.net/FcRpM/ 在我的笔记本电脑上的 Google Chrome 中工作,但在移动 HTC one S(安卓 4.1,GPS 关闭,通过移动网络定位并启用 wifi),通过 WiFi 连接到互联网.
其他 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.
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模板网!
使用 GPS 获取用户的当前位置Get user#39;s current location using GPS(使用 GPS 获取用户的当前位置)
requestLocationUpdate() 抛出的 IllegalArgumentExceptionIllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 抛出的 IllegalArgumentException)
LocationManager 的 getLastKnownLocation 有多可靠,多久更How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新
如何检测位置提供者?GPS 或网络提供商How to detect Location Provider ? GPS or Network Provider(如何检测位置提供者?GPS 或网络提供商)
在应用启动期间获取当前位置Get current location during app launch(在应用启动期间获取当前位置)
locationManager.getLastKnownLocation() 返回 nulllocationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)