如何通过在编辑文本中使用 android 示例中的 Google 地图获取位置名称 或密码地址作为输入来查找纬度和经度我输入城市名称或城市密码,它将显示它的纬度和经度。
问问题
227 次
2 回答
1
请检查这一点,这将有助于您 从城市名称中获取纬度和经度,或者如何从地址中找到纬度和经度?
于 2012-11-30T10:06:08.757 回答
1
假设存在地理编码器服务,这是一个更简单的解决方案:
final Geocoder geocoder = new Geocoder(this);
final String zip = "90210";
try {
List<Address> addresses = geocoder.getFromLocationName(zipCode, 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
// Use the address as needed
String message = String.format("Latitude: %f, Longitude: %f",
address.getLatitude(), address.getLongitude());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
} else {
// Display appropriate message when Geocoder services are not available
Toast.makeToast(this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// handle exception
}
//地址
Geocoder coder = new Geocoder(this);
List<Address> address;
try {
address = coder.getFromLocationName(strAddress,5);
if (address == null) {
return null;
}
Address location = address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
return p1;
}
http://android-er.blogspot.in/2011/02/get-address-from-location-using.html
于 2012-11-30T10:12:31.513 回答