为什么地理定位在移动浏览器上不起作用? [英] Why does geolocation not work on mobile browsers?

查看:86
本文介绍了为什么地理定位在移动浏览器上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用HTML5 geolocation获取用户的位置. 在台式机上,它运行良好,但是在我所有的移动设备(三星笔记,三星银河S4和Iphone 6)上,它都无法正常工作并且没有显示error对象.

I am trying to get the location of the user with HTML5 geolocation. On Desktop it works great, but on all my mobile devices (Samsung note, Samsung galaxy S4 And Iphone 6) its not working and not showing the error object.

这是我的代码:

function showPosition(position) {
    var coor = position.coords.longitude+", "+position.coords.latitude;
    alert(coor);
}
function errorPosition(error) {
    alert(error);
}
function toggleGeolocation() {
    navigator.geolocation.watchPosition(showPosition,errorPosition);
}

它要求获得地理位置许可,然后单击允许"(gps正在运行).可能是什么问题?

It asks to get permission for geolocation and I click allow (gps is working). What could be the problem?

我在所有设备上都使用Google Chrome.

I am using Google Chrome on all devices.

推荐答案

尝试使用此代码,它应该可以工作.

Try with this code, it should work.

var successHandler = function(position) { 
alert(position.coords.latitude); 
alert(position.coords.longitude); 
}; 

var errorHandler = function (errorObj) { 
alert(errorObj.code + ": " + errorObj.message); 

alert("something wrong take this lat " + "26.0546106 ); 
alert("something wrong take this lng " +-98.3939791); 

}; 

navigator.geolocation.getCurrentPosition( 
successHandler, errorHandler, 
{enableHighAccuracy: true, maximumAge: 10000});

这篇关于为什么地理定位在移动浏览器上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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