我正在编写一个
Android应用程序,将动态可用的纬度和逻辑坐标转换为人类可读的位置.
例如,12.2,4.5位于英国伦敦市中心.关于粒度,我希望能够至少找到城市 – >城镇.或者如果没有,至少在城市,
有人可以建议有什么解决方案可用于此问题.
解决方法
试试这个:
//listenner location changed
private class MyLocListener implements LocationListener {
public void onLocationChanged(Location location) {
if (location != null) {
Log.d("LOCATION CHANGED",location.getLatitude() + "");
Log.d("LOCATION CHANGED",location.getLongitude() + "");
}
}
}
//Get address base on location
try{
Geocoder geo = new Geocoder(youractivityclassname.this.getApplicationContext(),Locale.getDefault());
List<Address> addresses = geo.getFromLocation(latitude,longitude,1);
if (addresses.isEmpty()) {
yourtextfieldname.setText("Waiting for Location");
}
else {
if (addresses.size() > 0) {
Log.d(TAG,addresses.get(0).getFeatureName() + "," + addresses.get(0).getLocality() +"," + addresses.get(0).getAdminArea() + "," + addresses.get(0).getCountryName());
}
}
}
catch (Exception e) {
e.printstacktrace();
}