Is there a way to retrieve auid of location for apple map venues?

258 Views Asked by At

I want to open apple map for specific location/venue and to do so I'm doing

 if let url = URL(string: "maps://?address=Railway%20Station%20Area,%20Surat,%20395003,%20Gujarat,%20India&auid=4338464186124767060&ll=21.205538,72.840954&lsp=9902&q=Surat%20Railway%20Station&t=m") {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
 }

enter image description here

I can open map using same latitude longitude, but it will only appear as simple annotation without any detail in location card of apple map

 if let url = URL(string: "maps://?ll=21.205538,72.840954&lsp=9902&q=Surat%20Railway%20Station&t=m") {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
 }

enter image description here

it turn out that only thing required for mapItem to appear as apple map defined item/venue is auid in URL

so if I use only this (ie. url only with auid), it will still open venue perfectly with all apple map associated details.

 if let url = URL(string: "maps://?auid=4338464186124767060") {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
 }

so is there any way to fetch auid of venues for apple map? can we get it using latitude & longitude? Is there any other way to redirect venue to apple map with all the related info, not just simple annotation?

1

There are 1 best solutions below

2
Sachin Singh On

Try the below code

import MapKit

let location = CLLocationCoordinate2D(latitude: 37.3318, longitude: -122.0312)

let searchRequest = MKLocalSearch.Request()
searchRequest.naturalLanguageQuery = "Apple Park"
searchRequest.region = MKCoordinateRegion(center: location, latitudinalMeters: 1000, longitudinalMeters: 1000)

let search = MKLocalSearch(request: searchRequest)

search.start { response, error in
    guard let mapItems = response?.mapItems, let firstItem = mapItems.first else {
        print("No results found")
        return
    }
    
    print("Name: \(firstItem.name ?? "")")
    print("Address: \(firstItem.placemark.title ?? "")")
    print("AUID: \(firstItem.pointOfInterestCategory?.rawValue ?? ""):\(firstItem.url?.lastPathComponent ?? "")")
}