【问题标题】:Find polygon of City or region on Map在地图上查找城市或区域的多边形
【发布时间】:2019-02-11 08:13:57
【问题描述】:

我想在城市或用户在地图上搜索的区域周围绘制边界。我正在使用 Google Place API 来查找位置的纬度和经度。但我也想要城市或地区的边界。所以我可以在那个区域周围画一个多边形来显示。

例如,如果用户搜索“美国纽约”,我想在地图上绘制仅覆盖纽约市的叠加层。

我可以在 ios 中使用任何 API 来查找地图上的整个区域吗?

【问题讨论】:

    标签: ios swift mapkit google-places-api


    【解决方案1】:

    Google 不提供此类 API,但您可以使用 OpenStreetMap 以 geojson 格式获取城市的多边形坐标。

    您可以将响应转换为由多个库(如 GEOSwift)在地图上使用。

    例子:

    https://nominatim.openstreetmap.org/search.php?q=New+York&polygon_geojson=1&format=json

    let url = URL(string: "https://nominatim.openstreetmap.org/search.php?q=New+York&polygon_geojson=1&format=json")!
    
    let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
      guard let data = data else { return }
      print(String(data: data, encoding: .utf8)!) // Here convert the data to show on map
    }
    
    task.resume()
    

    【讨论】:

      猜你喜欢
      • 2017-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 2014-01-15
      • 2015-10-29
      • 1970-01-01
      相关资源
      最近更新 更多