PhoneGap的。无法启动地理定位服务 [英] PhoneGap. Failed to start Geolocation service

查看:184
本文介绍了PhoneGap的。无法启动地理定位服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PhoneGap的版本:2.0.0。 Android的API级别16(4.0.3版本)。 code样品,提示错误:

  navigator.geolocation.getCurrentPosition(的onSuccess,onError的,{enableHighAccuracy:真});功能的onSuccess(位置){
    的console.log('北纬:'+ position.coords.latitude);
    的console.log('经度:'+ position.coords.longitude);
}功能onError的(错误){
    的console.log('出现了错误:'+返回Error.message);
}

总是让模拟器中的错误 ,错误code 2 无法启动地理定位服务。即使发送的GPS坐标通过的 Android的控制台 DDMS

Android清单的权限:

 <使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>


解决方案

您仅在模拟器中进行测试呢?地理定位服务总是失败在我的Andr​​oid模拟器,但不是一个真正的设备上。

编辑:请尝试使用以下code

  document.addEventListener(deviceready,onDeviceReady,FALSE);功能onDeviceReady(){
    navigator.geolocation.getCurrentPosition(myPositionSuccess,myPositionError,{maximumAge:300000,超时:10000,enableHighAccuracy:真});
};

PhoneGap version: 2.0.0. Android API level 16 (4.0.3 version). Code sample which prompts an error:

navigator.geolocation.getCurrentPosition(onSuccess, onError, {enableHighAccuracy:true});

function onSuccess(position) {
    console.log('latitude: '+ position.coords.latitude);
    console.log('longitude: '+ position.coords.longitude);                  
}

function onError(error) {
    console.log('Appeared error : '+ error.message);                
}

Always getting an error in emulator Failed to start Geolocation service, error code 2. Even if send GPS coordinates through Android console or DDMS

Android manifest permissions:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

解决方案

Are you testing this on the emulator only? The Geolocation Service always fails in my Android emulator but not on a real device.

EDIT: Please try using the following code

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(myPositionSuccess, myPositionError, {maximumAge: 300000, timeout:10000, enableHighAccuracy : true});
};

这篇关于PhoneGap的。无法启动地理定位服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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