9***@qq.com
9***@qq.com
  • 发布:2024-01-23 16:14
  • 更新:2024-05-23 17:44
  • 阅读:174

native.js 获取android定位,onLocationChanged改变时候出错

分类:Native.js
    var context = plus.android.importClass("android.content.Context");  
            var locationManager = plus.android.importClass("android.location.LocationManager");  
            var Criteria = plus.android.importClass("android.location.Criteria");  
            var main = plus.android.runtimeMainActivity();  
            var mainSvr = main.getSystemService(context.LOCATION_SERVICE);  
            var gpsProvider = mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER); //检查是否开启了GPS  
            var loc = mainSvr.getLastKnownLocation(locationManager.GPS_PROVIDER);  

            var locationListener = plus.android.implements("android.location.LocationListener", {  
                "onLocationChanged": function(location) {  
                    var latitude = plus.android.invoke(location, "getLatitude");  
                    var longitude = plus.android.invoke(location, "getLongitude");  
                    var getAccuracy = plus.android.invoke(location, "getAccuracy");  
                    var gpsLocation = "lat:" + latitude + ",lng:" + longitude + "getAccuracy" +  
                        getAccuracy;  

                    callBack(getAccuracy, latitude, longitude);  

                },  
                //GPS开启的时候调用    
                "onProviderEnabled": function(res) {  

                    console.log("GPS开启调用:" + JSON.stringify(res));  
                },  
                //GPS关闭的时候调用    
                "onProviderDisabled": function(res) {  

                    console.log("GPS定位模块关闭,将无法获取经纬度信息:" + JSON.stringify(res));  
                },  
            });  

            // locationManager.GPS_PROVIDER 只使用GPS,locationManager参数可以自己百度      
            mainSvr.requestLocationUpdates(locationManager.GPS_PROVIDER, 3000, 0, locationListener);

onLocationChanged发生改变时候,location是{
"UUID": "Invocation144667845",
"TYPE": "JSBObject",
"className": "java.util.ArrayList"
}
通过 plus.android.invoke(location, "getLatitude");获取的latitude 为null,

怎么能解析出这个location?

2024-01-23 16:14 负责人:无 分享
已邀请:
黄Adai

黄Adai

博主您好,native.js获取android定位 可以获取到了嘛?

要回复问题请先登录注册