Geocoder g = new Geocoder(this, Locale.getDefault());
java.util.List<android.location.Address> result = null;
// testing
try{
result = g.getFromLocation(43.324722,21.903333, 1);
if (result.size() > 0) {
selectedCity = result.get(0).getLocality();
}else
//no city found
}catch(Exception ex)
{
}
i am using above code to get city value in android but it always show no city found any one guide me what c开发者_JAVA技巧ould be the problem?
public void getAddress(double lat, double lng) {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address obj = addresses.get(0);
String add = obj.getAddressLine(0);
GUIStatics.currentAddress = obj.getSubAdminArea() + ","
+ obj.getAdminArea();
GUIStatics.latitude = obj.getLatitude();
GUIStatics.longitude = obj.getLongitude();
GUIStatics.currentCity= obj.getSubAdminArea();
GUIStatics.currentState= obj.getAdminArea();
add = add + "\n" + obj.getCountryName();
add = add + "\n" + obj.getCountryCode();
add = add + "\n" + obj.getAdminArea();
add = add + "\n" + obj.getPostalCode();
add = add + "\n" + obj.getSubAdminArea();
add = add + "\n" + obj.getLocality();
add = add + "\n" + obj.getSubThoroughfare();
Log.v("IGA", "Address" + add);
// Toast.makeText(this, "Address=>" + add,
// Toast.LENGTH_SHORT).show();
// TennisAppActivity.showDialog(add);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
I am using this function for getting all the information related to latitude and longitude just pass the latitude and longitude in this function then you find your answer. I hope this is very help full to you.
精彩评论