我正在尝试将位置建议显示在“您想去哪里?”下的列表中的Apple地图中。 iOS 10中的NSUserActivity现在有一个mapItem属性,我用MKMapItem设置它,我用我用地理坐标和地名创建的MKPlacemark创建。
当我去Google地图时,地址名称不会出现。经过WWDC 2016,会议240几次,我仍然找不到我做错了什么。
答案 0 :(得分:1)
mapItem必须来自带有地理坐标和地名的MKLocalSearch请求。您从MKLocalSearchResponse获得的mapItems是Apple Maps将接受的mapItems。
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
}
})