Skip to content Skip to sidebar Skip to footer

How To Get Zip Code Or Area Code Of The Current Location In Android?

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

Solution 1:

You are clearly not using it right then...

Geocodergeocoder=newGeocoder(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.

Solution 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.

Geocodergeocoder=newGeocoder(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

Solution 3:

Read this carefully.

The getFromLocation method is what you need.

Post a Comment for "How To Get Zip Code Or Area Code Of The Current Location In Android?"