Mapbox 反向地理编码给出错误的结果?

问题描述 投票:0回答:0

我正在使用 Mapbox 构建乘客/司机应用程序。一切正常,除非我尝试对当前位置进行反向地理编码。这给我错误的结果错误的位置。

代码如下:

// VALocation.swift

import Foundation
import MapboxSearch

final class VALocation {

    fileprivate var result: SearchResult!

    public convenience init(with searchResult: SearchResult) {
        self.init()

        self.result = searchResult
    }

    func searchResult() -> SearchResult {
        return self.result
    }
}
import MapboxSearch

// ViewController vars
let searchEngine = SearchEngine()

// viewDidLoad
self.searchEngine.defaultSearchOptions = SearchOptions(countries: ["CU"], languages: ["es"], limit: 10)

// Function called when user tap get current location. Here I autocomplete a textField with reverse geocoding values & set self.pickUp
func getCurrentUserLocation() {
    guard let lastKnowLocation = self.mapManager.getLastKnowLocation() else {
        return
    }
   
    // lastKnowLocation = <+23.05375215,-82.44208426> +/- 3.54m (speed 0.00 mps / course 328.01) @ 21/2/23 10:24:09 p.m. hora estándar de Cuba
    print("lastKnowLocation: \(lastKnowLocation.coordinate)")

    let options = ReverseGeocodingOptions(point: lastKnowLocation.coordinate, countries: ["CU"], languages: ["es"])
    self.searchEngine.reverseGeocoding(options: options) { result in
        switch result {
            case .success(let results):
                guard let result = results.first else {
                    return
                }

                Async.main {
                    let vaLocation = VALocation(with: result)
                    self.currentPickUp = vaLocation
                    self.tfPickUp.text = vaLocation.searchResult().address?.formattedAddress(style: .short) ?? vaLocation.searchResult().name
                    print("Reversed: \(vaLocation.searchResult().coordinate)")
                    // print: CLLocationCoordinate2D(latitude: 23.024011611938477, longitude: -82.47828674316406) <- Wrong lat/lon (would be the same)
                }
            case .failure(let error):
                print(error)
        }
    }
}

我不知道我做错了什么或者我需要配置什么才能获得预期的结果。任何帮助将不胜感激。

ios swift mapbox reverse-geocoding mapbox-ios
© www.soinside.com 2019 - 2024. All rights reserved.