1

I am building an app that needs to access the user's zip code after getting the latitude and longitude. How can I get the zip using lat and lng?

felix
  • 454
  • 9
  • 19
  • 1
    You are going to need to use a service which can map latitude and longitude to a zip code. Keep in mind that zip codes can change for many reasons, e.g. a redistricting after an election. – Tim Biegeleisen Jun 02 '16 at 04:39

1 Answers1

0

In addition to native Geocoder class you can use Geocoding API web service. The web service has a reverse geocoding functionality:

https://developers.google.com/maps/documentation/geocoding/intro?hl=en#ReverseGeocoding

So you can specify latitude,longitude and a result type that you would like to get back.

In your use case it should be something similar to:

https://maps.googleapis.com/maps/api/geocode/json?latlng=37.8959524%2C-80.349527&result_type=postal_code&key=YOUR_API_KEY.

In Android you can use AndroidHttpClient class to execute HTTP request:

https://developer.android.com/reference/android/net/http/AndroidHttpClient.html

xomena
  • 31,125
  • 6
  • 88
  • 117