使用GPS的Phonegap中的地理定位 [英] Geolocation in Phonegap using GPS

查看:144
本文介绍了使用GPS的Phonegap中的地理定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用phonegap应用程序中的地理位置。高精度和省电模式打开时,我可以轻松获得位置。但它在GPS中工作时会出错。请帮忙。我陷入了困境。



我将超时时间设置为60000毫秒。但是,即使这样,它也没用。



代码是 -

 函数Geolocation(){} 

Geolocation.options = {
maximumAge:60000,
timeout:15000,
enableHighAccuracy:true
};

Geolocation.errorMessage ='无法获取位置数据。确保位置服务在高精度模式下启用。如果启用,请尝试关闭/打开位置服务并再次打开此页面;

Geolocation.update = function(){
navigator.geolocation.getCurrentPosition(Geolocation.updateSuccess,Geolocation.highAccuracyError,Geolocation.options);
}

Geolocation.highAccuracyError = function(err){
if(err.code == 3){
var options = Geolocation.options;
options.enableHighAccuracy = false;
options.timeout = 15000;

navigator.geolocation.getCurrentPosition(Geolocation.updateSuccess,Geolocation.lowAccuracyError,options);
}
}

Geolocation.lowAccuracyError = function(err){
Geolocation.currentLocation = null;
}

Geolocation.updateSuccess = function(position){
Geolocation.currentLocation = {};
Geolocation.currentLocation.latitude = position.coords.latitude;
Geolocation.currentLocation.longitude = position.coords.longitude;
}

预先致谢

>必须打开所有位置服务,包括GPS卫星,Google的位置服务和Quick GPS。否则,你会得到那个超时错误。

我认为谷歌有意破坏了它。它不会那样。



2)使用GPS时,您必须 运动 - 至少走20英尺(即使它在一个圆圈内),而且你必须拥有至少3颗卫星的现场直线。大多数人通过在一个开放的区域解决这个最后的问题 - 比如足球场或者停车场。

杰西


I am working with geolocation in phonegap application. I get the location easily when High Accuracy and Battery saving mode is ON. But it gives error while working in GPS. Please help. I am stuck in it.

I applied the timeout upto 60000 milliseconds. But it didnot work even then.

The code is -

function Geolocation(){}

Geolocation.options = {
    maximumAge: 60000, 
    timeout: 15000, 
    enableHighAccuracy: true
};

Geolocation.errorMessage = 'Unable to get location data. Ensure that the location services are enabled in high accuracy mode. If enabled, try turning off/on location services and open this page again';

Geolocation.update = function() {
        navigator.geolocation.getCurrentPosition(Geolocation.updateSuccess, Geolocation.highAccuracyError, Geolocation.options);
}

Geolocation.highAccuracyError = function(err) {
    if (err.code == 3) {
        var options = Geolocation.options;
        options.enableHighAccuracy = false;
        options.timeout = 15000;

        navigator.geolocation.getCurrentPosition(Geolocation.updateSuccess, Geolocation.lowAccuracyError, options);
    }
}

Geolocation.lowAccuracyError = function(err) {
    Geolocation.currentLocation = null;
}

Geolocation.updateSuccess = function(position) {
    Geolocation.currentLocation = {};
    Geolocation.currentLocation.latitude = position.coords.latitude;
    Geolocation.currentLocation.longitude = position.coords.longitude;
}

Thanks in advance

解决方案

@megha, with the GPS there are two issues.

1) On Android, you must turn on all the location services, including GPS satellites, Google's location service, and Quick GPS. Otherwise, you will get that timeout error.

I think google broke it on purpose. It did not used to be that way.

2) When using GPS, you must be in motion - walking around for at least 20 feet (even if it is in a circle), And you must have line-of-site of at least 3 satellites. Most people get around this last problem by being in an open area -- like a soccer field or parking lot.

Jesse

这篇关于使用GPS的Phonegap中的地理定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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