Basic Searching for iOS

  1. Developing on the new Arm-based Apple Silicon (M1) Macs requires building and running on a physical iOS device or using an iOS simulator running iOS 13.7, e.g. iPhone 11. This is a temporary limitation in Google Maps SDK for iOS, and as such also a limitation in MapsIndoors, due to the dependency to Google Maps.
  2. Note: Due to a bug in CocoaPods it is necessary to include the post_install hook in your Podfile described in the PodFile post_install wiki.

Searching through your MapsIndoors data is an integral part of a great user experience with your maps. Users can look for places to go, or filter what is shown on the map.

Searches work on all MapsIndoors geodata. It is up to you to create a search experience that fits your use case. To aid you in this, there are a range of filters you can apply to the search queries to get the best results. E.g. you can filter by Categories, search only a specific part of the map or search near a Location.

See the full list of parameters:

Parameter Description Class
take Max number of Locations to get MPFilter
Skip Skip the first number of entries MPFilter
categories A list of Categories to limit the search to MPFilter
Parents A list of Building or Venue IDs to limit the search to MPFilter
Types A list of Types to limit the search to MPFilter
Bounds Limits the result of Locations to a bounding area MPFilter
Floor Limits the result of Locations to be on a specific Floor MPFilter
Near Sorts the list of Locations on which Location is nearest the point given MPQuery
Depth The Depth property makes it possible to get "x" amount of descendants to the given parent. The default for this is 1 (eg. Building > Floor) MPFilter

Example of Creating a Search Query

let filter = MPFilter.init()
let query = MPQuery.init()
query.query = "Office"
query.near = MPPoint.init(lat: 57.057964, lon: 9.9504112)
query.take = 1

MPLocationService.sharedInstance().getLocationsUsing(query, filter: filter) { (locations, error) in
if let location = locations?.first {

}
}

All three return a list of Locations from your Solution matching the parameters they are given. The results are ranked upon the 3 following factors:

  • If a "near" parameter is set, how close is the origin point to the result?
  • How well does the search input text match the text of the result (using the "Levenshtein distance" algorithm)?
  • Which kind of geodata is the result (e.g. Buildings are ranked over POIs)?

This means that the first item in the search result list will be the one matching the 3 factors best and so forth.

Display Search Results on the Map

When displaying the search results it is helpful to filter the map to only show matching Locations. Matching Buildings and Venues will still be shown on the map, as they give context to the user, even if they aren't selectable on the map.

Filter the Map to Display Searched Locations on the Map

let filter = MPFilter.init()
let query = MPQuery.init()
query.query = "Office"
query.near = MPPoint.init(lat: 57.057964, lon: 9.9504112)
query.take = 1

MPLocationService.sharedInstance().getLocationsUsing(query, filter: filter) { (locations, error) in
myMapControl.searchResult = locations
}

Clear the Map of Your Filter

After displaying the search results on your map you can then clear the filter so that all Locations show up on the map again.

Example of Clearing Your Map Filter to Show All Locations Again

myMapControl.clearMap()