详细问题描述
版本更新到最新版本,
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
权限已开
native.js
var context = plus.android.importClass("android.content.Context");
var LocationManager = plus.android.importClass("android.location.LocationManager");
var ArrayList = plus.android.importClass("java.util.ArrayList");
var Criteria = plus.android.importClass("android.location.Criteria");
//var LocationListener=plus.android.importClass("android.location.LocationListener");
//var locationListener =new LocationListener();
var Location = plus.android.importClass("android.location.Location");
var main = plus.android.runtimeMainActivity();
var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
//var a = mainSvr.isProviderEnabled(LocationManager.GPS_PROVIDER);
/*mainSvr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, {
"onStatusChanged":function( name,value,a ){
console.log( "Invoked Object’s name: "+name ); // 输出“Invoked Object’s name: Tester”
}
})*/
//var b = mainSvr.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
//console.log("LocationManager.GPS_PROVIDER=" + a)
//console.log("LocationManager.NETWORK_PROVIDER=" + b)
var criteria = new Criteria();
// 设置定位精确度 Criteria.ACCURACY_COARSE 比较粗略, Criteria.ACCURACY_FINE则比较精细
criteria.setAccuracy(Criteria.ACCURACY_FINE);
// 设置是否需要海拔信息 Altitude
criteria.setAltitudeRequired(true);
// 设置是否需要方位信息 Bearing
criteria.setBearingRequired(true);
// 设置是否允许运营商收费
criteria.setCostAllowed(true);
// 设置对电源的需求
criteria.setPowerRequirement(Criteria.POWER_LOW);
//var a=plus.android.invoke(providers, ArrayList);
//console.log(a);
var bestProvider = mainSvr.getBestProvider(criteria, true);
最后一步返回null
0 个回复