我試圖獲取我當前位置的街道名稱,但似乎無法獲取它。從Android中的地址/位置對象獲取街道名稱
我用這個方法來檢索地址:
public Address getAddressForLocation(Context context, Location location) throws IOException {
if (location == null) {
return null;
}
double latitude = location.getLatitude();
double longitude = location.getLongitude();
int maxResults = 1;
Geocoder gc = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gc.getFromLocation(latitude, longitude, maxResults);
if (addresses.size() == 1) {
return addresses.get(0);
} else {
return null;
}
}
,然後我可以做這樣的事情。 address.getLocality()
和address.getPostalCode()
但我想要的是街道名稱。就像「Potterstreet 12」一樣。當我打印AddressLine(0)和AddressLine(1)時,我只能得到郵政編碼,城市和國家。
如何檢索我目前所在職位的街道名稱?
呀,像我上面說的,當我打印getAddressLine(0)和(1)我得到的郵遞區號,城市和國家。沒有街道名.. – Galip 2010-11-23 14:23:26
對不起,我沒有注意到它。也許你可以嘗試通過模擬器發送另一個位置的經緯度,並檢查是否可以看到一些返回的街道名稱。 – ccheneson 2010-11-23 14:27:51
也許你也可以增加maxResult來檢查其他結果包含的信息。 – ccheneson 2010-11-23 14:29:47