4

I am trying to make place suggestions appear in Apple Maps in the list under "Where do you want to go?". NSUserActivity in iOS 10 now has a mapItem property and I'm setting it with an MKMapItem that I create from an MKPlacemark that I made with geo coordinates and the place name.

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

CamQuest
  • 833
  • 9
  • 16

1 Answers1

1

The mapItem must be from an MKLocalSearch request that takes your geo coords and place name. The mapItems that you get from the MKLocalSearchResponse are ones that Apple Maps will accept.

    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
        }
    })
CamQuest
  • 833
  • 9
  • 16
  • I'm running into the same issue: if I generate a MKMapItem by sharing a location from Maps into my app, and then this same map item is shared back to Maps via NSUserActivity.mapItem, it doesn't show the place name or seem to encode geographic details. – Zoë Smith Jan 15 '18 at 18:24