swift 有没有办法为苹果Map获取场馆的位置标识符?

9gm1akwq  于 2023-02-28  发布在  Swift
关注(0)|答案(1)|浏览(117)

我想打开苹果Map的具体位置/地点,并这样做,我正在做

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

我可以打开Map使用相同的纬度经度,但它只会出现作为简单的注解没有任何细节的位置卡苹果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)
 }

事实证明,mapItem显示为Apple Map定义项目/地点所需的唯一条件是URL中的auid
因此,如果我只使用这个(即. url只与auid),它仍然会打开地点与所有苹果Map相关的细节完美。

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

那么有没有办法为苹果Map获取场馆的auid呢?我们可以用经纬度来获取它吗?有没有其他的方法来将场馆重定向到苹果Map,并包含所有相关的信息,而不仅仅是简单的注解呢?

qlckcl4x

qlckcl4x1#

尝试以下代码

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

相关问题