[英]How to load GeoJSON on a google map?
I have the following json file that has been parsed successfully on GEO Lint 我有以下已在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]
]]}}]}
My map is created in the ngOnInit{} part of the component: 我的地图是在组件的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();
}
The last call to getSiteandPoints function retrieve the data in geoJson format and displays it : 对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);
});
The GEO data is not displayed on the map. GEO数据未显示在地图上。 Could someone help me to find out why ?
有人可以帮我找出原因吗? I tried layers, loadGeoJson method ... in vain.
我尝试了图层,loadGeoJson方法...是徒劳的。
I thank you in advance for your help. 预先感谢您的帮助。
[1]: http://geojsonlint.com/
Finally, the problem was fixed. 最终,问题得以解决。 GeoJSON uses Lat, Lng in this order instead of Lng, Lat order.
GeoJSON按此顺序使用Lat,Lng而不是Lng,Lat顺序。 My file was displayed in Ethiopia...
我的档案显示在埃塞俄比亚...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.