如何从地址中找到纬度和经度?
问题描述:
我想在 Google 地图中显示地址的位置.
I want to show the location of an address in Google Maps.
如何使用 Google Maps API 获取地址的纬度和经度?
How do I get the latitude and longitude of an address using the Google Maps API?
答
public GeoPoint getLocationFromAddress(String strAddress){
Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;
try {
address = coder.getFromLocationName(strAddress,5);
if (address==null) {
return null;
}
Address location=address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
(double) (location.getLongitude() * 1E6));
return p1;
}
}
strAddress
是一个包含地址的字符串.address
变量保存转换后的地址.
strAddress
is a string containing the address. The address
variable holds the converted addresses.