IOS 10 NSUserActivity, Location Suggestions - MKMapItem not showing on maps

I'm trying to make suggestions that appear on Apple Maps in the list under the "Where do you want to go?" Section. NSUserActivity in iOS 10 now has a mapItem property, and I set it using MKMapItem, which I create from MKPlacemark, which I made with geo-coordinates and the name of the place.

The place name does not appear when I switch to Maps, as it should be. Having gone through WWDC 2016, session 240 several times, I still cannot find what I'm doing wrong.

+4
source share
1 answer

mapItem MKLocalSearch, - . MapItems, MKLocalSearchResponse, - , 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
        }
    })
+1

Source: https://habr.com/ru/post/1650951/


All Articles