All docschevron-rightSearch SDK for iOSchevron-rightarrow-leftGuideschevron-rightDiscover

Discover

lightning
Private preview

The Discover Search for iOS is in a private preview. Contact sales team if you are interested in the Discover Search.

The Discover SDK for iOS gives you the tools you need to add POI (Points of Interest) search to your application. Whether your users need to search for cafes nearby, parking in another city, or Electric Vehicle (EV) charging stations along their route, the Discover SDK will help you to provide functionality with just a few lines of code.

Discover Search use cases

  1. Search nearby. This use case allows users to quickly search for POIs nearby a specified geographical point, such as the user’s location. For example, you can enable your users to discover cafes, shops, and parks within walking distance.
  2. Search in the area. This use case will help your users to discover POI in a selected area, such as the user's current map view. If your user is searching for hotels in Paris, for example, search in the area will enable them to discover hotels by navigating the map.
  3. Search along the route. This navigation use case enables users to search for POI, such as Electric Vehicle (EV) charging stations, while driving between two or more points.

We have a ready-made sample app that you can try in Xcode with Discover Search and other scenarios. We encourage you to install and try it for yourself.

example
Full example of Discover Search

Learn how to integrate the Discover Search with MapKit and Search UI components in a sample app.

chevron-right

Integration

guide
Installation guide

Before using any of Mapbox's Search products, you need to do some common installation steps. Please follow this guide, then continue with the steps below.

chevron-right
  1. The main entry-point class is called Discover, you will need to instantiate this class first:
let discover = Discover(accessToken: mapboxAccessToken)
  1. Create the Discover.Query.Category instance. You can pick one of the predefined constants or instantiate it with the textual POI's category canonical name.
let query = Discover.Query.Category.coffeeShopCafe

or

let query = Discover.Query.Category.canonicalName("charging_station")

Note that the list of valid canonical names is not final and might be changed while the API is in beta. The link to the list will be available soon.

  1. Search for the POIs. The function parameters will vary depending on the use case.
  • For the Search nearby use case you will have to provide geographic position represented by the CLLocationCoordinate2D type:
let userLocation: CLLocationCoordinate2D = retrieveUserLocation()
discover.search(for: query, proximity: userLocation) { result in ... }
  • For the Search in the area use case you will have to provide a region represented by BoundingBox instance:
let currentRegion: BoundingBox = currentBoundingBox
discover.search(for: query, in: currentRegion) { result in ... }
  • And for the Search along the route use case you will have to provide a route represented by a list of points:
let routeOptions: RouteOptions = .init(
    route: buildRoute(),
    time: calculateRouteTime()
)
discover.search(for: query, route: routeOptions) { result in ... }
  1. Process the Discover Search response. The search() function returns either error or value:
discover.search(for: query, route: routeOptions) { result in
    switch result {
    case .success(let results):
        self.processDiscoverResults(results)
            
    case .failure(let error):
        debugPrint(error)
    }
}
glossary
API Reference

For more information, see the full API reference for the iOS Search SDK.

chevron-right