Search

Places

You can also search places around a specific coordinate in a radius or in a Bounding Box.
Here's an example on how to do it.

Note: to request more places for the same request, use SYSearchMorePlacesSession

extension DemoSearch  {

    func placesRequestLocation() -> SYSearchPlacesRequest {
        let location = SYGeoCoordinate(latitude: 48.142596, longitude: 17.125206)
        let request = SYSearchPlacesRequest(location: location, radius: 10000, tags: [SYPlaceCategoryPetrolStation, SYPlaceCategoryPharmacy])
        request.maxResultsCount = 22
        return request
    }

    func placesRequestBoundingBox() -> SYSearchPlacesRequest {
        let box = SYGeoBoundingBox(bottomLeft: SYGeoCoordinate(latitude: 48.139466, longitude: 17.103821),
                                   topRight: SYGeoCoordinate(latitude: 48.149452, longitude: 17.118079))
        let request = SYSearchPlacesRequest(boundingBox: box, tags: [SYPlaceCategoryRestaurant])
        request.maxResultsCount = 14
        return request
    }

    func places() {
        let session = prepareValidSession() // reuse existing session, if it's valid

        let request = placesRequestLocation() //or placesRequestBoundingBox()

        session.finish(byRequestingPlaces: request) {
            (places: [SYPlace]?, morePlacesSession: SYSearchMorePlacesSession?, status: SYSearchStatus) in

            guard status == .success, let places = places else { /* handle error */ return }

            // place results are ready
            places.forEach { (place) in
                self.printPlace(place)
            }

            // morePlacesSession can be saved and then used to get more places for the same request
        }
    }

    func printPlace(_ place: SYPlace) {
        print("")
        print("Place name: \(place.link.name); cat: \(place.link.category); gps: \(place.link.coordinate)")
        place.details.forEach { (arg0) in
            let (key, value) = arg0
            print("Place detail: \(key): \(value)")
        }
    }
}

Reverse Geocoding

Applications developed with the Sygic iOS SDK can perform offline and online geocoding, which allows geocode and reverse geocode requests to be performed event without an active data connection.

class SearchViewController: UIViewController {
    var reverseSearchResults: [SYReverseSearchResult] = []

    // Create an instance of SYReverseSearch
    let reverseSearch = SYReverseSearch()

    // Example of your method to perform reverse geocoding for specific coordinate
    func reverseSearch(at coordinate: SYGeoCoordinate) {

        // Perform request for coordinate
        self.reverseSearch.reverseSearch(with: coordinate) { [weak self] (reverseSearchResults, error) 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
            }
        }
    }
}