我正在尝试让苹果地图中的场所建议在“你想去哪里?”下的列表中显示。iOS 10中的NSUserActivity现在具有mapItem属性,我将其设置为一个MKMapItem,该MKMapItem由使用地理坐标和地点名称创建的MKPlacemark创建。
但是,在我进入地图后,地点名称没有出现,这本应该出现的。经过多次查看WWDC 2016,第240会话后,我仍然找不到我的错误之处。
mapItem必须来自于一个带有地理坐标和地点名称的MKLocalSearch请求。从MKLocalSearchResponse获取的mapItems是Apple Maps可接受的。
let coordinate = CLLocationCoordinate2D(latitude: 38.89005200, longitude: -77.00251600)
var points = [MKMapPointForCoordinate(coordinate)]
let mapRect = MKPolygon(points: &points, count: 1).boundingMapRect
let region = MKCoordinateRegionForMapRect(mapRect)
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "Supreme Court Historical Society"
request.region = region
let localSearch:MKLocalSearch = MKLocalSearch(request: request)
localSearch.start(completionHandler: { (response:MKLocalSearchResponse?, error:Error?) in
if error == nil {
activity.mapItem = response!.mapItems[0]
var userInfo = [String: AnyObject]()
userInfo["placemark"] = NSKeyedArchiver.archivedData(withRootObject: activity.mapItem.placemark)
activity.userInfo = userInfo
activity.contentAttributeSet?.supportsNavigation = true
activity.contentAttributeSet?.supportsPhoneCall = true
}
})