问题
I would like to get the zip code of the current location in android device for my app,any example or snippet on locating it. I have tried geocoder it gives lat & long position only.
回答1:
You are clearly not using it right then...
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
// lat,lng, your current location
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Now the list of Address
contains the closest known areas. The Address
object has the getPostalCode()
function. Grab the first object and find it's Postal code.
There you go.
回答2:
Check our the Geocoder class in Android. That class has getFromLocation method which works for me. You could use like the following in your activity.
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);
Address class docs
If it doesn't for some reason you should look for a reverse geocoding service
回答3:
Read this carefully.
The getFromLocation method is what you need.
来源:https://stackoverflow.com/questions/8442050/how-to-get-zip-code-or-area-code-of-the-current-location-in-android