我从 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 上。我对数据进行了以下检查:
- jsonlint(成功)
- geojsonhint(成功)
- >
geojsonlint
不确定/失败??? - > 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/