在Google地图上显示OpenStreetMap边界(使用v3 API) [英] Displaying OpenStreetMap boundaries on Google maps (using v3 api)

查看:291
本文介绍了在Google地图上显示OpenStreetMap边界(使用v3 API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我通过以下工具获得的GeoJSON数据在Google Map上显示城市边界.

I want to display the city boundary on the Google Map using GeoJSON data which I get using the following tools.

  1. 我去了nominatim.openstreetmap.org并搜索了一个城市(例如丹佛)
  2. 使用检索到的OSM ID(在本例中为253750),我已经使用在线工具(polygons.openstreetmap.fr)生成了GeoJSON文件-看起来像这样之后,我下载了文件,并尝试使用以下简单方法将此GeoJSON数据加载到我的地图中:

    After that, I've downloaded the file and tried to load this GeoJSON data into my map using simple:

    map.data.loadGeoJson(
                'http://domain.com/example.json');
    

    但是,在我的控制台中,我收到了一个错误:

    But, in my console I got an error:

    Uncaught InvalidValueError: not a Feature or FeatureCollection
    

    问题在于,即使以上工具生成了GeoJSON格式,也无法将其识别为标准格式.那么,这之间是否还有其他步骤?或者我在这里丢失了一些东西?

    The problem is that even though the above tool generates GeoJSON format, it's not recognized as the standard one. So is there an extra step between or I'm missing something here?

    推荐答案

    相关问题:您需要获取从Open Street Maps检索到的数据,并将其放入GeoJson解析器期望的Feature/FeatureCollection JSON中的位置:

    You need to take the data you retrieve from Open Street Maps and put it into the place in the Feature/FeatureCollection JSON that the GeoJson parser is expecting:

    var geoJson = {
      "type": "FeatureCollection",
      "features": [{
        "type": "Feature",
        "geometry": {},
        "properties": {}
      }];
    // where "geoJsonData" is the data you retrieved
    geoJson.features[0].geometry = geoJsonData;
    

    示例小提琴(带有来自发布链接的数据)

    这篇关于在Google地图上显示OpenStreetMap边界(使用v3 API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆