简体   繁体   English

无法在Android平台中调用地理位置插件

[英]Can not call geolocation plugin in Android platform

We use Worklight 6.2 or MobileFirst Foundation 7.0 and want to use navigator.geolocation.getCurrentPosition to get the GPS position, but there is not any response and no error, does anyone know why? 我们使用Worklight 6.2或MobileFirst Foundation 7.0,并且想要使用navigator.geolocation.getCurrentPosition来获取GPS位置,但是没有任何响应,也没有错误,有人知道为什么吗?

It works on older versions. 它适用于旧版本。

If you're not getting not success nor failure, and since you did not supply your implementation, I am left in thinking that you did not implement it correctly. 如果您没有获得成功或失败,并且由于您没有提供实现,那么我会认为您没有正确实现它。

I tested the below in the Android Emulator in MFPF 7.0, and it worked: 我在MFPF 7.0的Android仿真器中测试了以下内容,并且可以正常工作:

common\\main.js: common \\ main.js:

function wlCommonInit(){
    var options = {
            enableHighAccuracy: true,
            timeout: 5000,
            maximumAge: 0
    };

    navigator.geolocation.getCurrentPosition(success, error, options);
}

function success(pos) {
     var crd = pos.coords;
      alert('Your current position is:' + crd.latitude + " " + crd.longitude + " " + crd.accuracy);
}

function error(err) {
      alert('ERROR(' + err.code + '): ' + err.message);
}

And of course also added the following two permissions in AndroidManifest.xml: 当然还要在AndroidManifest.xml中添加以下两个权限:

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

If you're also testing in the emulator and getting a timeout, either increase the timeout value or force the location change in the DDMS view in Eclipse: https://stackoverflow.com/a/23152773/1530814 如果您还在模拟器中测试并获得超时,请增加超时值或在Eclipse的DDMS视图中强制更改位置: https : //stackoverflow.com/a/23152773/1530814

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM