android - 为什么我的 phone-gap 应用无法在某些 Android 设备上找到地理定位

标签 android cordova geolocation gps location

我创建了一个应用程序,它可以在 iPad/iPhone 上定位 GeoLocation 坐标,但在某些 Android 设备上无法执行此操作,即使该设备启用了 GPS。它适用于某些 Android 设备(例如 Samsung Galaxy tab SCH- I800) 并在其他一些(例如三星 Galaxy tab GT-P5113)上失败。

知道问题的可能原因是什么吗?

示例代码 fragment :

 <script type="text/javascript" 
 src="http://maps.google.com/maps/api/js?sensor=true"></script>
 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true">   </script>
    <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>

function onDeviceReady()
{  
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}

var onSuccess = function(position) {

            pos = new google.maps.LatLng(position.coords.latitude,
                                         position.coords.longitude);
            lat=position.coords.latitude;
            lng=position.coords.longitude;
            alert("lat: "+lat+" long "+lng); //i should get the lat/long here which i need to use further in my code   
         }

对于应用程序无法运行的设备,它将调用 onError 函数。

function onError(error) {

      alert("error code is: "+error.code);//it gives error code 3 when on such devices


        }

最佳答案

在这些 Android 设备上设置 watch 以使用 GPS 时,您需要设置“enableHighAccuracy”选项:

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

另请参阅此答案:Phonegap Android and GPS satellite

关于android - 为什么我的 phone-gap 应用无法在某些 Android 设备上找到地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14050697/

相关文章:

android - Android 应用程序上的 PowerMock + Mockito + Maven 显示 Dex 加载程序错误

ios - 如何使用 phonegap-videoplayer-plugin 播放 Youtube 视频?

c# - Newtonsoft.Json.JsonSerializationException(从“System.Data.SqlTypes.SqlDouble”上的 'Value' 获取值时出错)序列化 SqlGeography

iphone - iOS 6 破坏了 web 应用程序中的 GeoLocation(支持 apple-mobile-web-app)

Android 将位图旋转 90 度会导致图像被压扁。需要在纵向和横向之间进行真正的旋转

java - 获取 Android 设备上安装的应用程序数量?

javascript - 如何使 html5 文本字段显示数字键盘?

ios - 将 localforage-cordovasqlitedriver 安装到我的项目中时缺少 localforage.js 文件

iphone - 如何将地点与 CLGeocoder 的结果进行匹配?

java - 未找到默认 Activity 启动 Activity 时出错