我想使用GeoJSON数据在Google地图上显示城市边界,我使用以下工具。
之后,我已经下载了该文件,并尝试使用简单的方法将此GeoJSON数据加载到我的地图中:
map.data.loadGeoJson(
'http://domain.com/example.json');
但是,在我的控制台中我收到了一个错误:
Uncaught InvalidValueError: not a Feature or FeatureCollection
问题是即使上面的工具生成GeoJSON格式,它也不被认为是标准格式。那么我们之间是否会有一个额外的步骤,或者我错过了什么?
答案 0 :(得分:4)
相关问题:google maps addGeoJson from text field with js
您需要获取从Open Street Maps检索的数据并将其放入GeoJson解析器所期望的Feature / FeatureCollection JSON中的位置:
var geoJson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {},
"properties": {}
}];
// where "geoJsonData" is the data you retrieved
geoJson.features[0].geometry = geoJsonData;