【问题标题】:Why my phone-gap app has not been able to find geolocation on some of the Android device为什么我的 phone-gap 应用无法在某些 Android 设备上找到地理位置
【发布时间】:2012-12-27 06:57:34
【问题描述】:

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

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

示例代码sn-p:

 <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 cordova geolocation gps location


    【解决方案1】:

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

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

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

    【讨论】:

    • 我已经尝试过使用“enableHighAccuracy”。它也不适用于那个。另外我认为这个属性与准确性更相关,而我的问题是我没有得到任何位置只在那些设备。
    【解决方案2】:

    由于此错误,您的应用无法运行:

    PositionError.TIMEOUT

    当设备无法在 geolocationOptions 的 timeout 属性中指定的时间内检索到位置时返回。当与 geolocation.watchPosition 结合使用时,这个错误会在每超时毫秒被调用到 geolocationError 回调中。

    【讨论】:

    • 是的,它给出了超时错误,但仅在某些特定设备上有效,而在其他设备上有效。这很奇怪,因为当我尝试使用该设备在地图上查找我的位置时,它向我显示了当前位置但未能即使在其他设备上显示该位置时,也可以对应用执行此操作。
    • 你需要这个代码吗:pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);?
    【解决方案3】:

    将“enableHighAccuracy”选项设置为 false,然后如果您收到代码 2 错误(您有时可能会遇到),只需

    前往

    菜单--->设置---->位置和安全

    然后检查

    使用无线网络。

    这已经解决了我的问题,希望它也能解决你的问题......!!

    【讨论】:

      【解决方案4】:

      如果我的项目和我的客户坚持认为他可以进入地图并且它几乎可以立即找到 Hus 的地理位置,而在我的应用程序中它需要很长时间或者不起作用,我就会遇到这个问题。

      解决方案是及时返回插件 git 存储库并找到已删除的 java 文件,并使用该版本。

      发生的事情是插件维护者刚刚使用了本地浏览器地理定位,基本上根本没有使用插件,但在某些手机中它只是不符合标准。另一种方法是在您的应用中使用人行横道。

      我知道这不是一个“好”的解决方案,但它是获得可接受的性能所必需的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多