【发布时间】:2016-03-26 01:05:20
【问题描述】:
如何从android中的给定地址获取纬度和经度。
我想从地址中获取某个地方的纬度和经度。我不想从 GPS 或网络中获取纬度和经度。
【问题讨论】:
-
请贴出您目前尝试过的代码。
标签: android latitude-longitude
如何从android中的给定地址获取纬度和经度。
我想从地址中获取某个地方的纬度和经度。我不想从 GPS 或网络中获取纬度和经度。
【问题讨论】:
标签: android latitude-longitude
您可以使用以下方法:
// get latlng from address
public LatLng getLocationFromAddress(String strAddress) {
Geocoder coder = new Geocoder(context, Locale.getDefault());
List<Address> address;
LatLng p1 = null;
try {
address = coder.getFromLocationName(strAddress, 5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new LatLng(location.getLatitude(), location.getLongitude());
return p1;
} catch (Exception e) {
e.printStackTrace();
}
return p1;
}
【讨论】: