POI details and categories
Request POI details
To fetch details on a certain POI, use the Search.requestPOIDetails(options:completion:)
API. It takes a POIDetailsOptions
struct as input. The only required parameter is an identifier for the POI, which can be obtained in the SearchResultID
of a SearchResult
.
Only results of the POI type
SearchResult
are supported by the POI details request API.
You can request POI details in different languages. See the list of supported languages.
Specify the desired response language when creating POIDetailsOptions
using a POIDetailsOptions.locale
parameter.
If no language is specified, categories are returned in English.
1let amsterdamCenter = CLLocationCoordinate2D(latitude: 52.377956, longitude: 4.897070)2let options = SearchOptions(3 query: "Restaurant",4 geoBias: amsterdamCenter,5 resultTypes: [.poi]6)78onlineSearch.search(options: options) { [weak self] result in9 switch result {10 case let .success(poiSearchResponse):11 guard let result = poiSearchResponse.results.first,12 let resultID = result.searchResultID.id,13 let poiID = try? POIID(id: resultID, source: result.searchResultID.source) else {14 return15 }1617 let poiDetailsOptions = POIDetailsOptions(18 poiID: poiID,19 locale: Locale(identifier: "en_GB")20 )2122 self?.onlineSearch.requestPOIDetails(options: poiDetailsOptions) { result in23 switch result {24 case let .success(poiDetailsResponse):25 // handle success26 break27 case let .failure(error):28 // handle error29 break30 }31 }3233 case let .failure(error):34 // handle error35 break36 }37}
As a result, you will get a POIDetailsResponse
that contains POIDetailsResponse.POIDetails
with an updated POIDetailsResponse.POIDetails.poi
property.
More detailed information about this service can be found in the Search API Place by ID documentation.
Request POI categories
The POI categories request is used to obtain a list of all POI categories and subcategories, together with synonyms. You can request categories in different languages. See the list of supported languages. More detailed information about this service can be found in the Search API POI Categories documentation.
To perform a call, you need to create POICategoryOptions
where you can specify the desired response language.
If no language is specified, categories will be returned in the system language and in English if the system language is unsupported.
let options = POICategoryOptions(locale: Locale(identifier: "en_GB"))
As you created the query, you can:
1let onlineSearch = OnlineSearchFactory.create(apiKey: "YOUR_TOMTOM_API_KEY")2onlineSearch.requestPOICategories(options: options) { result in3 switch result {4 case let .success(poiCategoriesResponse):5 // handle success6 break7 case let .failure(error):8 // handle error9 break10 }11}
As a result you will get a: POICategoryResponse
that contains an array of POICategory
s.