- Developers
- Mobile SDK
- iOS
- Search
Search
- Move to section
Geocoding and reverse Geocoding
Applications developed with the Sygic iOS SDK can perform offline geocoding, which allows geocode and reverse geocode requests to be performed without an active data connection. This is done automatically when an active data connection is not available, as long as the map and database information have been previously downloaded.
class SearchViewController: UIViewController {
var reverseSearchResults = [SYReverseSearchResult]()
// Example of your method to perform reverse geocoding for specific coordinate
func reverseSearch(at coordinate: SYGeoCoordinate) {
// Create an instance of SYReverseSearch
let reverseSearch = SYReverseSearch()
// Perform request for coordinate
reverseSearch.reverseSearch(with: coordinate) { (reverseSearchResults) in
self.reverseSearchResults = reverseSearchResults
// Example of accessing reverse geocoding results description
if let firstResult = reverseSearchResults.first {
let resultDescription = firstResult.resultDescription // Contains textual description of the found result
let countryIsoCode = resultDescription.countryIso
let city = resultDescription.city
let street = resultDescription.street
let houseNumber = resultDescription.houseNumber
}
}
}
}
Offline Search
The Sygic iOS SDK includes a Search API which provides functionality to search and obtain more information about places in the real world. Note that offline search is supported when a data connection is unavailable, if the data required to perform the search has been previously downloaded. Geocoding APIs resolve a free-formatted text query to an SYGeoCoordinates, while reverse geocoding APIs resolve from an SYGeoCoordinates to geographic data.
class SearchViewController: UIViewController {
var searchResults = [SYSearchResult]()
func search(for searchQuery: String, at location: SYGeoCoordinate) {
// Create an instance of SYSearch
let search = SYSearch()
// Create SYSearchRequest with string to search for and location where the search should focus
let searchRequest = SYSearchRequest(query: searchQuery, atLocation: location)
searchRequest.connectivity = .offline // set .online when you are connected and don't have any maps downloaded
searchRequest.maxResultsCount = 50 // Optionally: specify maximum number of results
// Perform search request.
search.start(searchRequest) { (searchResults, resultState) in
if resultState == .error {
// Handle error state
}
// Process results
self.searchResults = searchResults
}
}
}
- Previous article: Navigation
- Next article: API Reference