How to get zip code or area code of the current location in android?

风流意气都作罢 提交于 2019-12-01 05:33:05

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.

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

Read this carefully.

The getFromLocation method is what you need.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!