iOS 16地图开发:本地搜索与路线规划全解析
1. iOS 16中使用MapKit进行本地搜索
在iOS 16里,借助MapKit的本地搜索功能,能够利用自然语言字符串开展地图搜索。下面是一段示例代码,用于搜索“Pizza”相关的地点:
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = "Pizza"
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start(completionHandler: {(response, error) in
if error != nil {
print("Error occurred in search: \(error!.localizedDescription)")
} else if response!.mapItems.count == 0 {
print("No matches found")
} else {
print("Matches found")
for item in response!.mapItems {
print("Name = \(item.name)")
print("Phone = \(item.phoneNumber)")
}
}
})
上述代码的执行步骤如下:
超级会员免费看
订阅专栏 解锁全文
696

被折叠的 条评论
为什么被折叠?



