mapbox / mapbox-search-ios

Search SDK for iOS with preconfigured UI in Swift
https://docs.mapbox.com/ios/search/guides/
Other
15 stars 20 forks source link

An error occurs when AddressAutofill is used to query address information by location #118

Closed GG-beyond closed 1 year ago

GG-beyond commented 1 year ago
    let centerCoordinate = CLLocationCoordinate2D(latitude: -34.005676, longitude: 138.795836)//mapView.centerCoordinate
    addressAutofill.suggestions(for: centerCoordinate,with: AddressAutofill.Options()) { [weak self] result in
        guard let self = self else { return }
        switch result {
        case .success(let suggestions):
            if let first = suggestions.first {
                self.addressAutofill.select(suggestion: first) { [weak self] result in
                    guard let self = self else { return }

                    if case .success = result {
                    } else {
                    }
                }
            }
        case .failure(let error):
            print("error = \(error)")
        }

error = generic(code: 422, domain: "MapboxCoreSearchErrorDomain", message: "Type \"countryregionpostcodedistrictplacelocalityneighborhoodaddressstreetpoi\" is not a known type. Must be one of: country, region, place, district, locality, postcode, neighborhood, address, poi, poi.landmark")

GG-beyond commented 1 year ago
    let engine = SearchEngine()
    func getLocationAddress() {
        engine.reverseGeocoding(options: ReverseGeocodingOptions(point: CLLocationCoordinate2D(latitude: -35.490594, longitude: 138.795836),types: [.address],languages: [])) { [weak self] result in
            guard let self = self else { return}
            switch result {
            case .success(let suggestions):
                print("suggestions = \(suggestions)")
                if let first = suggestions.first {
                    print("first = \(String(describing: first.address))")
                }
            case .failure(let error):
                print("error = \(error)")
            }
        }
    }

There's another way to do it

GG-beyond commented 1 year ago
    /// Start searching for query with provided options
    /// - Parameters:
    ///   - coordinate: point Coordinate to resolve
    ///   - options: if no value provided Search Engine will use options from requestOptions field
    final public func suggestions(for coordinate: CLLocationCoordinate2D, with options: MapboxSearch.AddressAutofill.Options? = nil, completion: @escaping (Result<[MapboxSearch.AddressAutofill.Suggestion], Error>) -> Void)

Why?

kried commented 1 year ago

Hi @GG-beyond

Thank you for the report. The problem is caused by the default types, used in the AdressAutofill request.

As a temporary workaround until the fix in the SDK is released, you could use reverse geocoding requests directly on SearchEngine, without the use of AdressAutofill.

sarochych commented 1 year ago

Hi @GG-beyond,

We've released a new version of SDK and there is a fix for the issue you reported. Please, check this out.

GG-beyond commented 1 year ago

👍🏻