0
我想要一個示例代碼,可以讓我們找到與導航系統相同的導航系統,並按照名稱進行搜索。從我們所在的位置到我們設定的目的地的位置。如何從Android輸入位置名稱獲取Latlng
我想要一個示例代碼,可以讓我們找到與導航系統相同的導航系統,並按照名稱進行搜索。從我們所在的位置到我們設定的目的地的位置。如何從Android輸入位置名稱獲取Latlng
使用這種方法
/**
* Get list of address by latitude and longitude
* @return null or List<Address>
*/
public List<Address> getGeocoderAddress(Context context)
{
if (location != null)
{
Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);
try
{
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
return addresses;
}
catch (IOException e)
{
//e.printStackTrace();
Log.e("Error : Geocoder", "Impossible to connect to Geocoder", e);
}
}
return null;
}
問候 行家
您可以使用以下方法 -
public String getLatLonByAddress(String addr) {
Geocoder geoCoder = new Geocoder(this);
List<Address> address = null;
try {
address = geoCoder.getFromLocationName(addr, 5);
}
catch (IOException e) {
e.printStackTrace();
}
if (address == null) {
return null;
}
Address location = address.get(0);
return location.getLatitude() + "/" + location.getLongitude();
}
http://stackoverflow.com/a/20166820/1777090 – 2014-09-03 07:00:59