[英]How to load GeoJSON on a google map?
我有以下已在GEO Lint上成功解析的json文件
{"type":"FeatureCollection",
"features":[
{"type":"Feature",
"properties":{},
"geometry":
{"type":"Polygon",
"coordinates":[
[[43.252967,5.379856],
[43.249466,5.422988],
[43.245153,5.425048],
[43.239838,5.383804],
[43.252967,5.379856],
[43.252967,5.379856]
]]}}]}
我的地图是在组件的ngOnInit {}部分中创建的:
ngOnInit() {
this.map = new
google.maps.Map(document.getElementById('mapContainer'), {
center: {lat: 43.252967, lng: 5.379856},
zoom: 14,
disableDefaultUI: true,
zoomControl: true,
minZoom: 3,
maxZoom: 20,
draggable: true,
mapTypeId: 'terrain'
});
var customLayer = new google.maps.Data();
this.getSitesandPoints();
}
对getSiteandPoints函数的最后一次调用以geoJson格式检索数据并显示:
getSitesandPoints() {
this.pointsArray = [];
this.customerApi.getLocations(this.currentUser.id)
.subscribe((response) => {
this.locations = response;
console.log(JSON.stringify(this.locations[0].geoDefinition));
this.map.data.addGeoJson(this.locations[0].geoDefinition);
});
GEO数据未显示在地图上。 有人可以帮我找出原因吗? 我尝试了图层,loadGeoJson方法...是徒劳的。
预先感谢您的帮助。
[1]: http://geojsonlint.com/
最终,问题得以解决。 GeoJSON按此顺序使用Lat,Lng而不是Lng,Lat顺序。 我的档案显示在埃塞俄比亚...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.