我在 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。)为什么会这样?
已编辑:但是当我将请求更改为
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 (标识符:'<+21.84329084, +82.78786665> 半径 2237301.34',中心:<+21.84329084,+82.78786665>,半径:2237301.34m)\";\n}" ); }