Sorry, you need to enable JavaScript to visit this website.

Search examples

Have a look at our functional examples to see how easy it is to implement search features with the Maps SDK.
Speed up development by using our sample code snippets in your app. Try all of this out with the Maps SDK Examples app!

Allow your users to easily search for addresses and POIs in a single step.
Implement global search or near-me search in your mobile app so that it returns the best search results for your needs.
Global search uses the search functionality’s default settings . It doesn’t use the user’s position or other search parameters.

Sample use case: You use an app to search for a place. This search should not be limited in any way.
Use the code snippet below in your app to list general search results or display them on the map.

return FuzzySearchQueryBuilder.create(text).build();

 

Add the code snippet presented below to your app to get search results that are geo-biased for a
given location in a range specified by a radius.

return FuzzySearchQueryBuilder.create(text).withPreciseness(new LatLngAcc(position, STANDARD_RADIUS)).build();

 



image

Global address search functional example from Sample App

image

Near me address search functional example from Sample App

Help your users search for specific types of places with category search.

Sample use case: You are preparing for a long drive and would like to find gas stations nearby.
Use the code snippet below to try this in your app.

FuzzySearchQueryBuilder.create(text)
        .withPreciseness(new LatLngAcc(position, STANDARD_RADIUS))
        .withTypeAhead(true)
        .withCategory(true).build();

 

Below we present a exemplary application view utilizing Category Search.



image

Address search with category: Parking

image

Address search with category: Gas

image

Address search with category: ATM

Develop an international app that can be used in different languages. Enhance the search functionality with the language parameter so that the search returns results in a specific language.

Sample use case: If your mobile device is set to a particular language, you see it in your app as well.
Use the code snippet presented below to try this in your app.

return FuzzySearchQueryBuilder.create(text).withLanguage(lang).build();

 

Offer your users search suggestions while they type with the “typeahead” flag.

Sample use case: You were recommended a place to visit, but you can’t remember its name. You start searching in your app. After a few letters you see the place you’re looking for!
Use the code snippet below to try this in your app.

FuzzySearchQueryBuilder.create(text)
        .withPosition(position)
        .withTypeAhead(true).build();

 

Help your users even more with fuzzy search. Use the right fuzziness levels in your app to make it less sensitive to typos.

Sample use case: You occasionally make mistakes when typing. Your app still returns the desired search results.
Use the code snippet below to try this in your app.

  • Level 1 no spell checking

  • Level 2 is using normal n-gram spell checking. For example query "restrant" can be matched to
    "restaurant".

  • Level 3 is using sound-like spell checking, and shingle spell checking. Sound-like spell checking
    is for "rstrnt" to "restaurant" matching. Shingle spell checking is for "mountainview" to
    "mountain view" matching.

  • Level 4 doesn’t add any more spell checking function.

The search engine will start looking for a match on the level defined by minFuzzyLevel and will
stop searching at the level specified by maxFuzzyLevel.

FuzzySearchQueryBuilder.create(query)
.withPosition(position)
.withMinFuzzyLevel(1)
.withMaxFuzzyLevel(maxLevel).build();

 

Reverse geocoding

Sometimes you need to translate a coordinate into a human-readable street address. This is often used in tracking applications that receive a GPS feed from a device or asset and need to obtain the corresponding address. The reverse geocoding endpoint returns the address information described in the Reverse Geocoding API documentation on the Developer Portal.

Sample use case: You want to know the address of a place on the map. You press your finger on the map display, and address information appears in a balloon on the screen.
Use the code below to try this in your app:

SearchApi searchAPI = createSearchAPI();
ReverseGeocoderSearchQuery reverseGeocoderQuery =
        createReverseGeocoderQuery(latLng);

searchAPI.reverseGeocoding(reverseGeocoderQuery, revGeoSearchCallback);

Polygons for reverse geocoding

Combine Additional Data Provider queries with Reverse Geocoding queries to obtain extra data about specific
entityType like:

  • Country

  • CountrySubdivision

  • CountrySecondarySubdivision

  • CountryTertiarySubdivision

  • Municipality

  • MunicipalitySubdivision

  • Neighbourhood

  • PostalCodeArea

Sample use case: You want to display Country or Municipality boundaries.

Use the code below to try this in your app:

ReverseGeocoderSearchQuery reverseGeocoderQuery =
        createReverseGeocoderQuery(latLng.getLatitude(), latLng.getLongitude());

Observable<RevGeoWithAdpResponse> revGeoWithAdpResponseObservable =
        revGeoWithAdpRequester.rawReverseGeocoding(reverseGeocoderQuery)
                .subscribeOn(getWorkerScheduler())
                .filter(revGeoWithAdpResponse -> !revGeoWithAdpResponse.getRevGeoResponse().getAddresses().isEmpty())
                .doOnNext(this::updateUiWithResponse);

 

revGeoWithAdpRequester.toPolygonObservable(revGeoWithAdpResponseObservable)
        .observeOn(getObserverScheduler())
        .subscribe(polygon -> {
            tomtomMap.getOverlaySettings().addOverlay(polygon);
            getProgressDisplayable().hideInProgressDialog();
        }, error -> getProgressDisplayable().hideInProgressDialog())

 

The class RevGeoWithAdpRequester serves as a helper to create complex queries:

class RevGeoWithAdpRequester {

    private final static int DEFAULT_GEOMETRIES_ZOOM = 4;
    private final PolygonAdapter polygonAdapter = new PolygonAdapter();
    private final SearchApi searchApi;

    private int geometriesZoom = DEFAULT_GEOMETRIES_ZOOM;

    RevGeoWithAdpRequester(SearchApi searchApi) {
        this.searchApi = searchApi;
    }

    Observable<Polygon> toPolygonObservable(Observable<RevGeoWithAdpResponse> revGeoWithAdpResponseObservable) {
        return revGeoWithAdpResponseObservable
                .flatMap((Function<RevGeoWithAdpResponse, ObservableSource<Polygon>>) revGeoWithAdpResponse -> {
                    AdditionalDataSearchResult adpResult =
                            FuncUtils.first(revGeoWithAdpResponse.getAdpResponse().getResults()).get();

                    return createSpecificPolygonObservable(parseGeometryResult(adpResult));
                });
    }

    @NonNull
    @VisibleForTesting
    protected GeometryResult parseGeometryResult(AdditionalDataSearchResult adpResult) {
        final AtomicReference<GeometryResult> gr = new AtomicReference<>();
        adpResult.accept(result -> gr.set(result));
        return gr.get();
    }

    Observable<RevGeoWithAdpResponse> rawReverseGeocoding(ReverseGeocoderSearchQuery reverseGeocoderQuery) {
        return searchApi.reverseGeocoding(reverseGeocoderQuery)
                .toObservable()
                .filter(response -> !response.getAddresses().isEmpty()
                        && FuncUtils.first(response.getAddresses()).get()
                        .getAdditionalDataSources().getGeometryDataSource().isPresent())
                .flatMap(response -> {
                    final GeometryDataSource geometryDataSource =
                            FuncUtils.first(response.getAddresses()).get()
                                    .getAdditionalDataSources().getGeometryDataSource().get();
                    return searchApi.additionalDataSearch(createAdditionalDataSearchQuery(geometryDataSource))
                            .toObservable().flatMap(adpResponse ->
                                    Observable.just(new RevGeoWithAdpResponse(response, adpResponse)));
                })
                .filter(response -> response.isValid())
                .filter(response -> response.getRevGeoResponse().hasResults())
                .filter(response -> !response.getAdpResponse().getResults().isEmpty());
    }

    void setGeometriesZoom(int geometriesZoom) {
        this.geometriesZoom = geometriesZoom;
    }

    private AdditionalDataSearchQuery createAdditionalDataSearchQuery(GeometryDataSource geometryDataSource) {
        return AdditionalDataSearchQueryBuilder.create()
                .withGeometryDataSource(geometryDataSource)
                .withGeometriesZoom(geometriesZoom)
                .build();
    }

    private Observable<Geometry> createGeometryObservable(GeometryResult result) {
        return Observable.just(result)
                .filter(geometryResult -> geometryResult.getGeometryData().isPresent())
                .map(geometryResult -> geometryResult.getGeometryData().get())
                .filter(geoJsonObject -> geoJsonObject instanceof FeatureCollection)
                .map(geoJsonObject -> ((FeatureCollection) geoJsonObject).getFeatures())
                .filter(features -> !features.isEmpty())
                .map(features -> FuncUtils.first(features).get())
                .filter(feature -> feature.getGeometry().isPresent())
                .map(feature -> feature.getGeometry().get());
    }

    private Observable<Polygon> createPolygonsObservable(Geometry geometry) {
        return Observable.just(geometry)
                .filter(geo -> geo instanceof MultiPolygon)
                .map(geo -> (MultiPolygon) geo)
                .flatMap((Function<MultiPolygon, ObservableSource<com.tomtom.online.sdk.common.geojson.geometry.Polygon>>)
                        multiPolygon -> Observable.fromIterable(multiPolygon.getPolygons()))
                .map(polygon -> getPolygonAdapter().convertToMapPolygon(polygon));
    }

    private Observable<Polygon> createSinglePolygonObservable(Geometry geometry) {
        return Observable.just(geometry)
                .filter(geo -> geo instanceof com.tomtom.online.sdk.common.geojson.geometry.Polygon)
                .map(geo -> (com.tomtom.online.sdk.common.geojson.geometry.Polygon) geo)
                .map(polygon -> getPolygonAdapter().convertToMapPolygon(polygon));
    }

    @VisibleForTesting
    protected PolygonAdapter getPolygonAdapter() {
        return polygonAdapter;
    }

    private Observable<Polygon> createSpecificPolygonObservable(GeometryResult result) {
        Geometry geometry = createGeometryObservable(result).blockingFirst();
        return (geometry instanceof MultiPolygon) ?
                createPolygonsObservable(geometry) :
                createSinglePolygonObservable(geometry);
    }
}

 

Sample views utilizing entities retrieved by combining both services:



image

Boundaries for selected country

image

Boundaries for selected municipality

To cancel a pending search request in the Maps SDK, call:

searchService.cancelSearchIfRunning();

 

Search along the route

Allow your users to search for POIs along a planned route so they can add places to their rides optimally. This search is constrained by specifying the detour time and limiting the number of results. The minimum number of route points is 2.

Sample use case 1: You are driving from Amsterdam to Haarlem and you would like to find a gas station or an EV station to fuel or charge your car during your drive.

Sample use case 2: When planning your next trip, you would like to add a car repair station so you can fix something in your vehicle to drive safely.

Use the code below to try this in your app:

AlongRouteSearchQueryBuilder query = new AlongRouteSearchQueryBuilder(
        term,
        route.getCoordinates(),
        SEARCH_MAX_DETOUR_TIME);

query.withLimit(SEARCH_MAX_LIMIT);

SearchApi searchAPI = OnlineSearchApi.create(context);
searchAPI.alongRouteSearch(query.build(), alongRouteSearchCallback);

 

Sample views utilizing Search Along Route:



image

With term "PETROL_STATION"

image

With term "ELECTRIC_VEHICLE_STATION"

Allow your users to perform a free text search inside geometries specified by circles and/or polygons.

Sample use case: You are planing to visit the area of Amsterdam.  You need find a parking, an ATM and a grocery store in the city centre in Amsterdam and/or in the west part of the city.

Use the code below to try this in your app:

List<Geometry> geometries = new ArrayList<>();
geometries.add(new Geometry(new PolygonGeometry(DefaultGeometries.POLYGON_POINTS)));
geometries.add(new Geometry(new CircleGeometry(DefaultGeometries.CIRCLE_CENTER, DefaultGeometries.CIRCLE_RADIUS)));
GeometrySearchQuery query = new GeometrySearchQueryBuilder(term, geometries)
        .withLimit(SEARCH_RESULTS_LIMIT).build();

SearchApi searchAPI = OnlineSearchApi.create(context);
searchAPI.geometrySearch(query, geometrySearchCallback);

 

Sample views utilizing Geometry Search:



image

Geometry search with term: Parking

image

Geometry search with term: ATM

Entry points

Allow your users to display entry points using fuzzy search results.

Sample use case: A taxi driver wants to pick up a passenger from the specific entry point at the airport.

Use the code below to try this in your app:

for (EntryPoint entryPoint : fuzzySearchResult.getEntryPoints()) {
    SimpleMarkerBalloon markerBalloon = new SimpleMarkerBalloon(
            String.format(markerBalloonText, entryPoint.getType()));

    addMarkerWithIcon(entryPoint, markerBalloon, icon);
}

private void addMarkerWithIcon(EntryPoint entryPoint, SimpleMarkerBalloon balloon, Icon icon) {
    tomtomMap.addMarker(new MarkerBuilder(entryPoint.getPosition())
            .markerBalloon(balloon)
            .icon(icon));
}

 

Sample views utilizing entry points:



image

Entry points for the Amsterdam airport

image

Entry points for the Kalvertoren mall

Additional data

Allow your users to request extra data, like polygons representing administrative borders, for a set
of entities previously retrieved from an Search API. For more information, refer to the
Additional Data service
documentation.

Sample use case: You want to apply colors to geographic-boundary areas such as countries, cities or districts.

Use the code below to try this in your app:

FuzzySearchQuery fuzzySearchQuery = FuzzySearchQueryBuilder.create(term).build();

searchRequester.performAdpSearch(fuzzySearchQuery, responseConsumer);

 

Sample views utilizing entities retrieved from the Additional Data service:



image

Boundaries for Amsterdam

image

Boundaries for Poland

Allow your users to process synchronous batch search calls with the Batch Search
service integrated. When the service receives a request, it will respond as soon as the batch items
are calculated and there will be no possibility to retrieve the results later on.

Supported types of requests

  1. Geometry Search

  2. Fuzzy Search

  3. Reverse Geocoder

Different types of requests can be mixed in one batch request. The information about the limit of
queries, request processing time and other details are described in Batch Search
service documentation. An error in one of the batch requests causes the whole batch to fail.

Sample use case: You want to simultaneously search for different categories within different locations.

Use the code below to try this in your app:

//Using batch, it is possible to execute different search types:
//fuzzy, geometry or reverse geocoding. The order of responses
//is the same as the order in which the queries are added.
BatchSearchQueryBuilder batchQuery = new BatchSearchQueryBuilder();
batchQuery.withFuzzySearchQuery(createAmsterdamQuery(category));
batchQuery.withFuzzySearchQuery(createHaarlemQuery(category));
batchQuery.withGeometrySearchQuery(createHoofddropQuery(category));

final SearchApi searchApi = OnlineSearchApi.create(context);
searchApi.batchSearch(batchQuery.build(), batchSearchResultListener);

 

Sample views utilizing data retrieved using Batch Search service:


image

Search results for different locations