Skip to main content
Version: 5.0

Search

Using Mappedin SDK for iOS with your own map requires an Enterprise license. Try a demo map for free or refer to the Pricing page for more information.

The Mappedin SDK for iOS provides a way to search for locations and categories using their names, descriptions and tags. The search is performed locally on the device, meaning it can be used when a device is offline.

A complete class that uses the code snippets in this guide can be found in the Mappedin iOS Github repo: SearchVC.kt

Methods for Searching

MPISearchManager offers two different methods to perform a search, MPISearchManager.search and MPISearchManager.suggest.

The search method is used to search for locations and categories based on a query string. Results are returned as a List containing MPISearchResultLocations and MPISearchResultCategorys, which both extend from MPISearchResultCommon.

The suggest method is used to generate suggested search terms for a given query string and returns a List of MPISearchSuggestions that contains a String with the suggestion.

Understanding Search Results

Search results contain a score and details about how it was matched. When displaying the results to a user, the results should be sorted to show the highest score first.

Code Example

Below is a code sample that performs the following operations:

  1. Performs a search using the String query.
  2. Filters the results that contain locations (MPISearchResultLocation), removing categories (MPISearchResultCategory).
  3. Filters locations that contain the type of “tenant”. Note that location types will be unique to each venue and are chosen by the map administrator.
  4. Sorts the results by score with the highest score first.
mapView?.searchManager.search(query: searchText) {
results in
let searchLocations = results
// Filter the results that contain locations.
.compactMap { $0 as? MPISearchResultLocation }
// Filter locations that contain the type of “tenant”.
.filter({$0.object.type == "tenant"})
// Sort the results by score with the highest score first.
.sorted(by: {$0.score > $1.score})
}

A complete class that uses the code snippets in this guide can be found in the Mappedin iOS Github repo: SearchVC.kt