私はMKMapViewでMKLocalSearchを使用しています..次のように実装しています
extension MYClass: SendLocationDelegate{
func sendCoOrdinates(loccoordinate:CLLocation, placemark:CLPlacemark){
println(" Google VC coordinate is as \(loccoordinate.coordinate.longitude) \(loccoordinate.coordinate.latitude)")
let location:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude:loccoordinate.coordinate.latitude, longitude: loccoordinate.coordinate.longitude)
let theSpan : MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta:0.01)
let theRegion : MKCoordinateRegion = MKCoordinateRegion(center: location, span: theSpan)
self.mapView.setRegion(theRegion, animated: false)
let request = MKLocalSearchRequest()
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.startWithCompletionHandler({(response: MKLocalSearchResponse!,
error: NSError!) in
if error != nil {
println("Error occured in search: \(error.localizedDescription)")
} else if response.mapItems.count == 0 {
println("No matches found")
} else {
println("Matches found")
println("\(response)")
}
})
}
}
出力: Google VC 座標は 72.8561644 19.0176147 です。検索でエラーが発生しました: 操作を完了できませんでした。(MKErrorDomain エラー 1.)これはなぜですか?
EDITED:ただし、リクエストを次のように変更すると
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "india"
//request.region = mapView.region
let search = MKLocalSearch(request: request)
私は良い反応を得ます
{boundingRegion = ""; mapItems = ( " {\n isCurrentLocation = 0;\n name = India;\n placemark = \"India, India @ <+23.04117260,+78.89180550> +/- 0.00m, region CLCircularRegion (identifier:'<+21.84329084, +82.78786665> 半径 2237301.34'、中心:<+21.84329084、+82.78786665>、半径:2237301.34m)\";\n}" ); }