Search by Coordinate
Search by Coordinate
The Search SDK simplifies the process of performing a coordinate search that will return addresses, places, or Points of Interest (POIs) around a specific geographical coordinate.
Getting Started with Coordinate Search
GUIDE
Installation guide
Before utilizing any of Mapbox's Search products, there are some common installation steps that you need to follow. Refer to this guide, and then go ahead with the steps outlined below.
- The
PlaceAutocomplete
class serves as the primary access point for implementing coordinate search functionality. To begin, you must first create an instance of this class. You can do this by using the following Swift code:
let placeAutocomplete = PlaceAutocomplete(accessToken: mapboxAccessToken)
- To retrieve autocomplete suggestions based on a specific geographical location, you should provide the geographic coordinates represented by the
CLLocationCoordinate2D
type. Here's how you can do it:
let searchCoordinates: CLLocationCoordinate2D = prepareSearchCoordinates()
placeAutocomplete.suggestions(for: searchCoordinates) { result in ... }
- After initiating a request for autocomplete suggestions, you'll need to handle the response from the
suggestions()
method. This function will either return an error or a list of suggestions. Here's how you can process the response:
placeAutocomplete.suggestions(for: query) { result in
switch result {
case .success(let suggestions):
self.processSuggestions(suggestions)
case .failure(let error):
debugPrint(error)
}
}
GLOSSARY
API Reference
For more information, see the full API reference for the iOS Search SDK.
このpageは役に立ちましたか?