我试图在“您想去哪里?”下的列表中的Apple Maps中显示地点建议。 iOS 10中的NSUserActivity现在具有mapItem属性,并且将其设置为MKMapItem,该MKMapItem是由我使用地理坐标和地名创建的MKPlacemark创建的。

转到地图时,地名不会出现,应该显示。在经历了WWDC 2016,会议240次之后,我仍然找不到我做错的事情。

最佳答案

mapItem必须来自带有您的地理坐标和地名的MKLocalSearch请求。您从MKLocalSearchResponse获得的mapItem是Apple Maps将接受的mapItem。

    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
        }
    })

07-24 09:44