Java 科尔多瓦安卓经纬度误差

Java 科尔多瓦安卓经纬度误差,java,javascript,android,cordova,Java,Javascript,Android,Cordova,社区你好, 我在Android中为cordova 2.9.0创建了一个插件来获取位置坐标。 下面是我的代码 package com.appstudioz.realstate; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; import org.json.JSONArray; import org.json.JSONException; import andro

社区你好, 我在Android中为cordova 2.9.0创建了一个插件来获取位置坐标。 下面是我的代码

package com.appstudioz.realstate;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
public class GpsLocation extends CordovaPlugin {
public static final String NATIVE_ACTION_STRING="getLocation";
protected LocationManager locationManager;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
 locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if(NATIVE_ACTION_STRING.equals(action)){
            this.showCurrentLocation(callbackContext);
            return true;
        }
        return false;

}

    protected void showCurrentLocation(CallbackContext callbackContext) {

        String provider=locationManager.getBestProvider(new Criteria(), false);
        if(provider!=null){
            Location location = locationManager.getLastKnownLocation(provider);
            System.out.println("--------------in locationManager");
            if (location != null) {
                String message = String.format("Current Location",location.getLongitude(), location.getLatitude());
                System.out.println("--------------in showCurrenenter code heretLocation---"+message);
                callbackContext.success(message);`enter code here`
                //callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, message));

            }
            else{
                System.out.println("in showCurrentLocation error");
                callbackContext.error("Unable to get location.");
                //callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Unable to get location"));
            }
        }


    }   


    private LocationManager getSystemService(String locationService) {
        // TODO Auto-generated method stub
        return null;
    }

}
这是javascript文件

var gpsPlugin = { 
        callNativeFunction: function (success, fail, resultType) { 
          console.log("---------------------Working");
          return cordova.exec( success, fail, "GpsLocation", "getLocation", [resultType]); 
        } 
    };
我是从这条线打过来的

gpsPlugin.callNativeFunction(nativePluginResultHandler, nativePluginErrorHandler, 'test');
插件正在运行,但给出

09-21 09:22:19.154:E/Web控制台(2023):在NPObject上调用方法时出现未捕获错误。在file:///android_asset/www/js/cordova.js:863

若我并没有使用位置服务并从文件中传递字符串消息,那个么它永远不会给出上述错误

我已经浪费了几个小时调试这个,但无法找到问题。 请帮帮我


提前多谢

为什么您需要一个本地插件来获取当前位置?你不能使用Phonegap的内置功能吗?谢谢,我解决了getCurrentPosition不能在所有设备上工作的问题,这就是我创建插件的原因。