代码之家  ›  专栏  ›  技术社区  ›  Amr Eladawy Pierre Henry

如何在Mapbox Swift中设置要素类型?

  •  0
  • Amr Eladawy Pierre Henry  · 技术社区  · 7 年前

    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 在地图盒里斯威夫特?中国没有这样的财产 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 
    } 
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Guy Kogus    7 年前

    通过搜索 MapboxGeocoder.swift 项目我找到了 list of types . 他们是:

    • “国家”
    • “区域”
    • “地区”
    • “地点”
    • “地点”
    • “邻里”
    • “地址”
    • “poi.landmark”

    使现代化

    为了设置的选项类型 ReverseGeocodeOptions ,设置 allowedScopes

    let geocodeOptions = ReverseGeocodeOptions(coordinate: coordinate)
    geocodeOptions.allowedScopes = .pointOfInterest
    

    注意 允许范围 是一组类型,因此可以创建多个类型,例如。

    geocodeOptions.allowedScopes = [.pointOfInterest, .landmark]