- Developers
- Sygic Maps SDK
- Android
- Search
Search
Autocomplete, Geocoding and SearchPlaces
Applications developed with the Sygic SDK can use geocoding to transform textual query into geographical information. With the SearchManager you can perform three basic actions : Geocoding, ReverseGeocoding and Autocomplete. Please note that if you use the online services, you might want to define to send a request once every 300ms or so, otherwise some requests might end up with an error TOO_MANY_REQUESTS. The autocomplete engine works with few simple steps:
The search has SESSIONS (offline, online and hybrid):
A session has a limited lifetime. The lifetime follows this call graph:
[0..N] autocomplete requests
then either of
[1] do nothing -> close session
[1] geocode with location ID -> close session
[1] geocode with query -> close session
[1] search places with query -> [0..N] search places with continuation token -> close session
After finding the desired result in autocomplete, you can take its locationID and call Geocode with it to get more precise information about the location. If you do not need to use autocomplete and have the full string that you want to search for, just use Geocode straight away.
When searching for places, you can create a new placeRequest and use your position, the categories that you want to search for and several other arguments.
Simple examples:
ArrayList<String> categories = new ArrayList<>();
categories.add("SYTouristInformationOffice");
categories.add("SYMuseum");
GeoCoordinates position = new GeoCoordinates(51.510175, -0.122445);
PlaceRequest placeRequest = new PlaceRequest(position, categories, /*radius*/ 1000);
SearchRequest searchRequest = new SearchRequest("London Eye", new GeoCoordinates(51.510175, -0.122445));
Session session = search.newHybridSession(); // search was received via the SearchManagerProvider
session.autocomplete(searchRequest, new AutocompleteResultListener() {
@Override
public void onAutocomplete(@NotNull List<? extends AutocompleteResult> list) {
}
@Override
public void onAutocompleteError(@NotNull ResultStatus resultStatus) {
}
});
session.geocode(searchRequest, new GeocodingResultsListener() {
@Override
public void onGeocodingResults(@NotNull List<? extends GeocodingResult> list) {
}
@Override
public void onGeocodingResultsError(@NotNull ResultStatus resultStatus) {
}
});
session.searchPlaces(placeRequest, new PlacesListener() {
@Override
public void onPlacesLoaded(@NotNull List<Place> list, @Nullable String s) {
}
@Override
public void onPlacesError(@NotNull ResultStatus resultStatus) {
}
});
Reverse geocoding
Reverse geocoding is the opposite process to geocoding, meaning you query by geographical location and receive textual address of the location. You can define a filter if you do not want to take walkways into account or pass it an emptySet.
ReverseGeocoderProvider.getInstance(new CoreInitCallback<ReverseGeocoder>() {
@Override
public void onInstance(@NonNull ReverseGeocoder reverseGeocoder) {
reverseGeocoder.reverseGeocode(position, Collections.emptySet(), new ReverseGeocoder.ReverseGeocodingResultListener() { // do not forget to filter out the walkways if you do not want them
@Override
public void onReverseGeocodingResult(@NotNull List<? extends ReverseGeocodingResult> list) {
}
@Override
public void onReverseGeocodingResultError(@NotNull ReverseGeocoder.ErrorCode errorCode) {
}
});
}
@Override
public void onError(CoreInitException e) {
}
});
- Previous article: Navigation
- Next article: API Reference