我正在使用 aGeocoder
来定位我的位置,其中包括地址、邮政编码和国家/地区值。
但getFromLocation(latitude,longitude,number)
返回 null,即使我使用已知的位置属性(纬度:40,645081 经度:22,988892)。
我正在使用 Eclipse 在 AVD(API 级别 7)上测试我的应用程序。
提前致谢。
这是该getFromLocation
函数使用位置的片段。
private void updateWithNewLocation(Location location){
String latLongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
String addressString = "No address found";
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + lat + "\nLong:" + lng;
//double latitude = 73.147536;
//double longitude = 0.510638;
Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(lat, lng, 1);
Log.v("TRY_BODY", "All addresses are: " + addresses);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Log.v("IF_BODY", "All addresses are: " + addresses);
Address address = addresses.get(0);
for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
}
} catch (IOException e) {}
}
else {
latLongString = "No location found";
}
myLocationText.setText("Current Position:\n"+latLongString + "\n" + addressString);
}