Zip Code to LatLng

I’m currently trying to figure out how to take a zip code and convert it into a LatLng point. My app currently retrieves the user’s locale (to find the current country) so that the zip code within that country can be utilized. Anyways, the idea is to get the zip code from the user, then place a draggable marker in the center of that area.

At the moment, the app has the ability to simply use the user’s current location, but I decided to add the manual location feature due to some test users preferring not to give location access to their apps. Searching the documentation, I can’t readily find how to do this on Android. Perhaps I’d be better off implementing an autocomplete feature to start with an address, but I thought the “Enter zip and drag where you’d like to center” would allow for more flexibility.

So the question being, how exactly would I take a zip and convert it to LatLng on Android? I had the idea that Geocoding would be involved, but there isn’t much info on the documentation on it aside from how to structure an https request.

Hi Jazttin.

It’s possible of course but when you will provide more information to the Search API, you will get better results. You can start from this simple code:

SearchApi searchApi = OnlineSearchApi.create(MainActivity.this);
// 94128 is SF International Airport zipcode. It'll show more places around the airport though. 
FuzzySearchQuery query = FuzzySearchQueryBuilder.create("94128").withCountry("US").build();
searchApi.search(query, new FuzzySearchResultListener() {
    @Override
    public void onSearchResult(FuzzySearchResponse results) {
        for (FuzzySearchResult result :
                results.getResults()) {
            Toast.makeText(MainActivity.this, result.getAddress().getPostalCode() + " " + result.getAddress().getFreeformAddress(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onSearchError(SearchError error) { }
});

Regards,
Mateusz