如何从经纬度获得完整的地址?我想从Android中的纬度和经度中获得以下值街道地址城市/州拉链完整地址如何做到这一点?
3 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
Geocoder geocoder;List<Address> addresses;geocoder = new Geocoder(this, Locale.getDefault()); addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5 String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()String city = addresses.get(0).getLocality();String state = addresses.get(0).getAdminArea(); String country = addresses.get(0).getCountryName();String postalCode = addresses.get(0).getPostalCode(); String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL
Smart猫小萌
TA贡献1911条经验 获得超7个赞
private String getCompleteAddressString(double LATITUDE, double LONGITUDE) { String strAdd = ""; Geocoder geocoder = new Geocoder(this, Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1); if (addresses != null) { Address returnedAddress = addresses.get(0); StringBuilder strReturnedAddress = new StringBuilder(""); for (int i = 0; i <= returnedAddress.getMaxAddressLineIndex(); i++) { strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n"); } strAdd = strReturnedAddress.toString(); Log.w("My Current loction address", strReturnedAddress.toString()); } else { Log.w("My Current loction address", "No Address returned!"); } } catch (Exception e) { e.printStackTrace(); Log.w("My Current loction address", "Canont get Address!"); } return strAdd; }
- 3 回答
- 0 关注
- 555 浏览
添加回答
举报
0/150
提交
取消