Search

VERSION 0.13.0
GENERAL AVAILABILITY

Fuzzy search is the default, generic search service. It can handle vague and imprecise inputs and supply results for:

  • Areas on the map (countries, states, cities).
  • Specific addresses with a street name and number (2501 Soquel Drive, Kalverstraat 23).
  • Address ranges on streets where address points are interpolated along the length of the street.
  • Streets.
  • Junctions, places where two streets intersect.
  • Point of interest (Restaurant, Sports Center).

Fuzzy search requests are built using the SearchOptions struct. The only required parameter for fuzzy search is the query string parameter. The other parameters are optional.

To get the best experience, consider:

  • Using geoBias to perform geo-biasing, which boosts the priority of results relevant to the user’s current location.
  • Using radius if geo-biasing is not strong enough to keep your results local to the user.
  • Using resultTypes to limit results to specific categories, e.g., POIs or addresses only.

More information about best practices is described at Best Practices. A detailed description of Fuzzy Search and its parameters can be found in the Search API Fuzzy Search documentation.

Once you have a SearchOptions object, provide it to the OnlineSearch.

1let options = SearchOptions(query: "Pizza")
2onlineSearch.search(options: options) { result in
3 switch result {
4 case let .success(searchResponse):
5 // handle success
6 break
7 case let .failure(error):
8 // handle error
9 break
10 }
11}

Search along a route

Use this search to find POIs along a specific route with the fuzzy search algorithm. The search is constrained by a time limit for detours from the route. The route must consist of at least 2 points. You can use the Routing module to create a route.

See the instructions in the planning a route. To create the request you need to create SearchOptions. The query, route, and maxDetourTime (in seconds, with a maximum of 3600) parameters are required. You can also specify more detailed options for the underlying Fuzzy Search. More information about Along Route Search is in the Search API Along Route Search documentation.

1let query = "ATM"
2let alongRouteSearchOptions = SearchOptions(
3 query: query,
4 route: route,
5 maxDetourDuration: Measurement.tt.seconds(600),
6 limit: 10
7)

Parameter completion: The completion closure is called after the response to the request has been processed. If no errors occurred, SearchResponse contains an array of categories and subcategories together with their translations and synonyms.

1onlineSearch.search(options: alongRouteSearchOptions) { result in
2 switch result {
3 case let .success(alongRouteResponse):
4 // handle success
5 break
6 case let .failure(error):
7 // handle error
8 break
9 }
10}

Autocomplete

Autocomplete helps users make more effective searches. It recognizes entities inside an input query and offers them as query terms. This improves the accuracy of the search results.

Autocomplete requests are built using the AutocompleteOptions struct. The required parameters are the query and the locale in which the autocomplete results should be returned. You can also provide optional parameters to perform a more accurate search, following similar recommendations as for fuzzy search. Also, see more information in the Search API Autocomplete documentation.

let options = AutocompleteOptions(query: "Piz", locale: Locale(identifier: "en_GB"))

Once you have an AutocompleteOptions object, provide it to the OnlineSearch.

1onlineSearch.autocomplete(options: options) { result in
2 switch result {
3 case let .success(autocompleteReponse):
4 // handle success
5 break
6 case let .failure(error):
7 // handle error
8 break
9 }
10}

The geometry search allows you to perform a free-form search inside one or more defined geographic areas (geometries). By default, POIs are returned as a result. For other result types, the idxSet parameter should be used.

There are two types of geometries that are supported:

  • PolygonGeometry - an array of coordinates of vertices.
    1let vertices: [CLLocationCoordinate2D] = [
    2 CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070),
    3 CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070),
    4 CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070),
    5 CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070),
    6]
    7let polygon = PolygonGeometry(vertices: vertices)
  • CircleGeometry - center coordinates and a radius in meters.
    let center = CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070)
    let circleGeometry = CircleGeometry(coordinate: center, radius: Measurement.tt.meters(1000))

Provide the geometries and query to initialize the SearchOptions by defining the searchAreas parameter.. You can also define optional parameters such as the number of results to return, language, and various constraints on what is searched for. More information about optional parameters and the geometry search can be found in the Search API Geometry Search documentation.

let options = SearchOptions(query: "Pizza", searchAreas: [.polygon(polygon)])

If the search was successful, the response is presented as a SearchResponse object. Otherwise, error is returned.

1let onlineSearch = OnlineSearch(apiKey: "REPLACE_WITH_YOUR_API_KEY")
2onlineSearch.search(options: options) { result in
3 switch result {
4 case let .success(geometrySearchResponse):
5 // handle success
6 break
7 case let .failure(error):
8 // handle error
9 break
10 }
11}