如何通过在Android中使用谷歌地图获取位置名称或密码地址作为输入来查找纬度和经度 例 在编辑文本中,我输入一个城市名称或城市的密码,它将显示它的纬度和经度。
答案 0 :(得分:1)
请检查一下,这对您有用[{3}}或get latitude and longitude from city name
答案 1 :(得分: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
}
// addr
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