Search code examples
swiftmapboxgeocode

Mapbox GeoCoder --> How to get nearby restaurants, hotels, shopping malls etc


I am using Mapbox Geocoder for searching places in our app. But, I also need to get all the nearby places like restaurants, hotels etc. Is it possible with Mapbox Geocoder?

This is the code we are using for forward geocode,

    let region = RectangularRegion(southWest:   CLLocationCoordinate2DMake(swlat, swlng), northEast: CLLocationCoordinate2DMake(nelat, nelng))

    let options = ForwardGeocodeOptions(query: input)
    options.allowedRegion = region --> To restrict search

I can do this with Google autocomplete,

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=1500&type=restaurant&keyword=cruise&key=API_KEY.

But, I can't use both Mapbox and Google.


Solution

  • The Geocoding API supports "category" search, although it's still marked as experimental. The documentation includes a list of the currently supported categories: https://docs.mapbox.com/api/search/#point-of-interest-category-coverage.

    You can either build your own implementation to query the geocoding endpoint directly, or use the Open Source MapboxGeocoder.swift which acts as a native wrapper for the API.


    ⚠️ Disclaimer: I currently work at Mapbox ⚠️