ios - 如何在 Mapbox Swift 中设置特征类型?
问题描述
默认情况下,使用 Mapbox Swift 列出附近的兴趣点会返回一个结果。将limit
增加到 10 会引发以下错误:
反向地理编码时,limit 必须与单个类型参数结合使用
这可以通过将特征类型传递为 来解决POI
。
curl -X GET 'https://api.mapbox.com/geocoding/v5/mapbox.places/55.274111,25.197139.json?
access_token=pk..&limit=10&types=poi'
如何types
在 Mapbox Swift 中设置?类中没有这样的属性ReverseGeocodeOptions
。
let options = ReverseGeocodeOptions(coordinate:
CLLocationCoordinate2D(latitude: 40.733, longitude: -73.989))
let task = geocoder.geocode(options) { (placemarks, attribution, error) in
guard let placemark = placemarks?.first else {
return
}
print(placemark.imageName ?? "")
// telephone
print(placemark.genres?.joined(separator: ", ") ?? "")
// computer, electronic
print(placemark.administrativeRegion?.name ?? "")
// New York
print(placemark.administrativeRegion?.code ?? "")
// US-NY
}
解决方案
通过搜索MapboxGeocoder.swift项目,我找到了types 列表。他们是:
- “国家”
- “地区”
- “区”
- “邮政编码”
- “地方”
- “地方”
- “邻里”
- “地址”
- “poi.地标”
- “宝”
更新
为了设置选项类型ReverseGeocodeOptions
,设置allowedScopes
属性。
let geocodeOptions = ReverseGeocodeOptions(coordinate: coordinate)
geocodeOptions.allowedScopes = .pointOfInterest
请注意,这allowedScopes
是一组类型,因此您可以创建多种类型,例如
geocodeOptions.allowedScopes = [.pointOfInterest, .landmark]
推荐阅读
- ssh - 如何修复谷歌珊瑚开发板 ssh 连接问题
- redux - Redux 异步操作:将初始调度放入 try 块有什么不同吗?
- php - 包括 php 链接不起作用 [localhost] php
- c++ - 如何找到总和满足要求的子序列?
- python - 如何使用 scrapy 下载 amazon-s3 图像
- python - 获取两个标签区间内的兄弟标签内容:]tag1; tag5 [ = tag2、tag3、tag4 与 Xpath -Python -Selenium
- python - 试图为python下载openCV,但它一直给我这个错误
- javascript - 在 React 钩子中排序后如何渲染数组
- java - MongoDB聚合与spring
- c++ - 尽管使用 cap_sys_nice,但无法将线程优先级设置为实时