javascript - 无法使用 Google map 数据层从源加载 geojson

标签 javascript google-maps google-maps-api-3 geojson

我从 publicly available dataset here 获得了一个 geoJSON 数据集我有 saved here .

当我将此数据从我系统上的文件加载到 Google map 数据层时:

var goldCoastData = new google.maps.Data({
    map: map,
    style: {
        icon: 'images/marker_gc.png',
        strokeColour: '#0b2430',
        strokeOpacity: 1,
        fillColor: '#ff534f',
        fillOpacity: 1
    }
});

$.ajax({
    type: 'GET',
    url: 'scripts/datasets/goldCoast_buildings.json',
    dataType: 'json'
}).done(function (data) {
    console.log(JSON.stringify(data));
    goldCoastData.addGeoJson(data);
});

数据未显示在 map 上。我对数据进行了以下检查:

  1. jsonlint(成功)
  2. geojsonhint(成功)
  3. > geojsonlint不确定/失败???
  4. > drag and drop失败

最佳答案

我发现google maps Data layer中添加的geoJson需要使用投影EPSG:4326 为了工作。我可以使用 url 末尾的 &SrsName=EPSG:4326 以这种格式从数据集中获取数据。

This links to data from the question in the correct format

根据@geocodezip 和@John Barça 对问题的评论,谷歌使用 EPSG:3857,所以这一定是某种怪癖,希望如此。

关于javascript - 无法使用 Google map 数据层从源加载 geojson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25197171/

相关文章:

javascript - 检测浏览器是否为 Android 的最轻量级方法是什么?

google-maps - 谷歌地图信息窗口最大宽度问题

java - 在android中的谷歌地图中获取最近的地铁站位置

javascript - 谷歌地图 → 手动 fitBounds

javascript - 按父 ID 递归搜索后代

javascript - 将字符串传递给 settimeout 是不好的做法吗?如果是,为什么?

javascript - 如何删除谷歌地图的位置框(左上角)?

javascript - Google 标记动画更改

javascript - 谷歌地图在 Firefox 中不显示

javascript - Google map 地点 API : TypeError: autocomplete is undefined