参考autojs的获取GPS定位的代码:
function getLocationLoop(){
//判断是否已经打开GPS模块
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//GPS模块打开,可以定位操作
var criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
var provider = locationManager.getBestProvider(criteria, true);
var location = locationManager.getLastKnownLocation(provider);
log("经度:"+location.getLongitude()+"\n纬度:"+location.getLatitude())
var gc = new android.location.Geocoder(context,java.util.Locale.getDefault());
var result = gc.getFromLocation(location.getLatitude(),location.getLongitude(),1);
log(result)
log(result.get(0).getAddressLine(0))
locationManager.requestLocationUpdates(provider, 1000, 10, new LocationListener({
onLocationChanged:
function(location){
log(location);
}
}));
}
}
使用getFromLocation()函数获得的Address类内容类似于这样的:
具体获得某一项信息的函数:
- getAdminArea() :返回状态首字母缩略词(“CA”,对于加利福尼亚州)
- getCountryCode() :返回国家ISO代码(“JP”,日本)
- getCountryName() :返回国家名称(“西class牙”,用于……西class牙)
- getFeatureName() :返回该位置的名称(如果有的话)(博物馆的“卢浮宫”)
- getLocality() :返回城市名称(“伦敦”)
- getPostalCode() :返回邮政编码(“94110”,在美国)
- getPremises() :???
- getSubAdminArea() :???
- getSubLocality() :???
- getSubThoroughfare() :???
- getThoroughfare() :返回街道和建筑物编号(“1600 Amphitheatre Parkway”)
网友评论