3
當我使用MapKit在Apple地圖和我的應用程序中進行搜索時,我得到了兩個不同的「紐約」結果。蘋果地圖和MapKit使用相同的API嗎?
它們是否都使用相同的api?
如果我在蘋果地圖上搜索「紐約」,它會將指針放在紐約市中心。但是,如果我使用MKLocalSearchRequest
和naturalLanguageQuery
搜索「紐約」,它會將指針放在一個位置,即使在曼哈頓也是如此。
代碼:
override func viewDidLoad() {
super.viewDidLoad()
self.mapView.delegate = self
localSearchRequest = MKLocalSearchRequest()
localSearchRequest.naturalLanguageQuery = "New York"
localSearch = MKLocalSearch(request: localSearchRequest)
localSearch.startWithCompletionHandler { (localSearchResponse, error) -> Void in
if localSearchResponse == nil || self.mapView == nil{
var alert = UIAlertView(title: "Not found", message: "Try again", delegate: self, cancelButtonTitle: "OK")
alert.show()
return
} else {
let location = CLLocationCoordinate2D(latitude: localSearchResponse.boundingRegion.center.latitude, longitude: localSearchResponse.boundingRegion.center.longitude)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegion(center: location, span: span)
self.mapView.setRegion(region, animated: false)
self.pointAnnotation = MKPointAnnotation()
self.pointAnnotation.coordinate = location
self.mapView.addAnnotation(self.pointAnnotation)
}
}
}
你顯然問錯了問題。你需要顯示你使用的代碼來產生對你來說不夠準確的結果,然後可能會問你如何使它更加準確。 – nhgrif
@nhgrif用代碼更新我的問題 –