Search code examples
androidhere-apigeocode

Proper query structure for GeocodeRequest in HERE Maps Android SDK?


Since version 3.0 of HERE Maps Android SDK, the GeocodeRequest takes a free-text query to do the Geocoding request process, however it is unclear what is the proper structure to pass the query. "country city" or "country, city" or "city country"... etc

In my implementation the user selects country/city and based on that I want to center a map on that country/city by doing a geocode request to get the GeoCoordinate from that location, so the question is how should I form the query so that the geocode request returns locations in its onComplete method, and also what is the accurate radius value?

My current implementation is as below

 String geoCodeQuery = String.format("%s %s",
                        selectedDestinationCity == null ? "" : selectedDestinationCity.getCity(),
                        selectedDestinationCountry == null ? "" : selectedDestinationCountry.getCountry());
 GeocodeRequest geocodeRequest = new GeocodeRequest(geoCodeQuery);

 geocodeRequest.setSearchArea(new GeoCoordinate(
                        selectedDestinationCountry.getCapitalCityCoordinate().getLatitude(),
                        selectedDestinationCountry.getCapitalCityCoordinate().getLongitude()), 5000);
                geocodeRequest.execute(new ResultListener<List<Location>>() {
                    @Override
                    public void onCompleted(List<Location> locations, ErrorCode errorCode) {
                        loadingDialog.dismiss();

                        if (errorCode == ErrorCode.NONE) {
                            if (locations.size() > 0) {
                                GeoCoordinate location = locations.get(0).getCoordinate();
                                addressModelBuilder.setLatitude(location.getLatitude());
                                addressModelBuilder.setLongitude(location.getLongitude());
                            }

                        }
                    }
                });

Appreciate your kind help.


Solution

  • An address in a standard format is sufficient (eg. City, State, Country). If the Geocoder is not returning the expected results, then you may be encountering a known Geocoder bug... please try using a small radius (eg. 1m) for setSearchArea().

    If however the GeoCodeRequest is not not yielding any results, then alternative requests to use are TextAutoSuggestionRequest or SearchRequest.

    TextAutoSuggestionRequest in an online-only query.

    SearchRequest works for both online/offline queries.

    These queries are likely used for the onebox queries at https://wego.here.com.