[英]Cannot find a differ supporting object '33.265625' of type 'number'
I have a Ionic App using google maps.我有一个使用谷歌地图的 Ionic 应用程序。 I am trying to get latitude and longitude from data json api for flight route and that data json api then inject that data to Google Maps polyline .我正在尝试从数据 json api 获取纬度和经度以获取飞行路线,然后将该数据 json api 注入到 Google Maps polyline 中。 Fetch data json api working fine without problem , but when l put objects inside Google Maps l get error Error: Cannot find a differ supporting object '33.265625' of type 'number'. NgFor only supports binding to Iterables such as Arrays.
获取数据 json api 工作正常没有问题,但是当我将对象放入谷歌地图时,我得到错误Error: Cannot find a differ supporting object '33.265625' of type 'number'. NgFor only supports binding to Iterables such as Arrays.
Error: Cannot find a differ supporting object '33.265625' of type 'number'. NgFor only supports binding to Iterables such as Arrays.
l use forEach to move through the array .我使用 forEach 在数组中移动。
my code :我的代码:
async getmarker(){
this.http.get('/v1/flightjson?flightId=201',{},{})
.then( data=>{
// this.latitude = JSON.parse(data.data).result.response.data.flight.track.latitude
// this.longitude = JSON.parse(data.data).result.response.data.flight.track
for(let datas of JSON.parse(data.data).result.response.data.flight['track']) {
this.longitude = datas.longitude
this.latitude = datas.latitude
console.log(this.longitude)
// Do something.
}
})
}
loadMap() {
let AIR_PORTS = [
this.latitude,
this.longitude
];
this.map = GoogleMaps.create('map_canvas');
let polyline: Polyline = this.map.addPolylineSync({
points: AIR_PORTS,
color: '#AA00FF',
width: 10,
geodesic: true,
clickable: true // clickable = false in default
});
polyline.on(GoogleMapsEvent.POLYLINE_CLICK).subscribe((params: any) => {
let position: LatLng = <LatLng>params[0];
let marker: Marker = this.map.addMarkerSync({
position: position,
title: position.toUrlValue(),
disableAutoPan: true
});
marker.showInfoWindow();
});
}
html html
<div id="map_canvas"></div>
for(let datas of JSON.parse(data.data).result.response.data.flight['track']) {
this.longitude = datas.longitude
this.latitude = datas.latitude
}
In above for
loop, I assume this.longitude
and this.latitude
will be arrays.在上面的for
循环中,我假设this.longitude
和this.latitude
将是数组。 You should push
elements inside this.longitude
and this.latitude
(as shown below), instead of replacing previous value.您应该push
元素push
this.longitude
和this.latitude
(如下所示),而不是替换之前的值。
this.longitude.push(datas.longitude);
this.latitude.push(datas.latitude);
You may be using these variables to iterate through different points on the map, as they are plain numbers, ngFor
will throw an error saying that content inside ngFor
should be iterable
.您可能正在使用这些变量来遍历地图上的不同点,因为它们是普通数字, ngFor
会抛出一个错误,指出ngFor
中的内容应该是iterable
。 Array
is an iterable
whereas number
is not. Array
是iterable
而number
不是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.