简体   繁体   English

找不到类型为“数字”的不同支持对象“33.265625”

[英]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();
    });
  }

my data json url 我的数据json url

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.longitudethis.latitude将是数组。 You should push elements inside this.longitude and this.latitude (as shown below), instead of replacing previous value.您应该push元素push this.longitudethis.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. Arrayiterablenumber不是。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到&#39;对象&#39;类型的不同支持对象&#39;[object Object]&#39; - Cannot find a differ supporting object '[object Object]' of type 'object' 找不到其他支持对象&#39;[对象对象] - Cannot find a differ supporting object '[object Object] 找不到类型为“object”的不同支持对象“[object Object]”。 - 上下文菜单问题 - Cannot find a differ supporting object '[object Object]' of type 'object'. - context menu issues Angular:*ngFor 循环给我错误:找不到类型为“object”的不同支持对象“[object Object]” - Angular: *ngFor loop giving me error: Cannot find a differ supporting object '[object Object]' of type 'object' 过滤多面阵列,但管道返回错误 - 找不到&#39;对象&#39;类型的不同支持对象&#39;[object Object]&#39; - Filtering a multifaceted array, but the pipe return an error - Cannot find a differ supporting object '[object Object]' of type 'object' 角度4无法找到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到可迭代对象,例如数组 - Angular 4 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular 9 找不到支持“对象”类型的 object“[对象对象]”的不同。 NgFor 仅支持绑定到诸如 Arrays 之类的 Iterables - Angular 9 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular 问题:找不到支持“object”类型的 object“[object Object]”的不同。 NgFor 仅支持绑定到诸如 Arrays 之类的 Iterables - Angular problem: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays 错误:找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到Iterables(如数组)如何解决 - error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays how to solve 在 Angular 上执行 GET 请求时出现此错误:找不到不同的支持 object '[object Object] - Getting this error when doing a GET request on Angular: Cannot find a differ supporting object '[object Object]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM