【问题标题】:Angular5 | XHR finished loading: GET "<URL>" keeps running角5 | XHR 完成加载:GET "<URL>" 继续运行
【发布时间】:2018-03-07 02:39:27
【问题描述】:

我有一个 angular 5 应用程序,由一个 api 支持,它提供了所选标记位置附近的快递员(出租车司机)的列表。直到今天,一切都运行良好,似乎它一直在从 api 请求快递员的位置。请求是从服务中的方法发出的。

以前有人遇到过这个问题吗?

组件:

ngOnInit() {
    this.loadMap();
    this.startMap();
    this.loadCustomerAddresses();
}
startMap(){

    google.maps.event.addListener(this.map, 'idle', () => {

      if(this.sourceConfirmed == false){
        this.locateSource();
      }else if(this.destinationConfirmed == false){
        this.locateDestination();
      }else if(this.addingNextDestination == true){
        this.destComponent.locateNextDestination();
      }else{
        return false;
      }
  })

locateSource(){

  this.markerSource = new google.maps.Marker({
    position: this.map.getCenter(),
    map: this.map,
    draggable: false
  });
  this.markerSource.setVisible(false);

  this.mapCenter = this.map.getCenter();
  this.markerSource.setPosition(this.mapCenter);
  this.sourceLat = this.markerSource.getPosition().lat();
  this.sourceLng = this.markerSource.getPosition().lng();
  this._orderService.getPlaceName(this.sourceLat, this.sourceLng).subscribe(
    name => {
      this.sourceAddress = name;
    }
  );

  this._orderService.loadCouriersNearby(this.mapCenter.lat(), this.mapCenter.lng()).subscribe(
    result => {
      if(result.status == 'success'){
        let couriers = result.couriers;
        this._zone.run(() => {
          this.couriersCount = couriers.length;
        });
        for (let courier of couriers) {
          let latLng = {lat: Number(courier.location.latitude), lng: Number(courier.location.longitude)};
          let courierMarker = new google.maps.Marker({
            position: latLng,
          })
          courierMarker.setMap(this.map)
          this.couriersMarkers.push(courierMarker);
        }
      }else{
        this._zone.run(() => {
          this.couriersCount = 0;
        });
      }
    }
  );
}

服务:

loadCouriersNearby(lat, lng){
  var url = 'http://my.domain.path';
  var headers = new HttpHeaders().set('x-mobile-token', this._cookieService.get('token'));
  var params = new HttpParams()
    .set('latitude', lat)
    .set('longitude', lng)

  return this.http.get(url, {headers: headers, params: params}).map(response=>response.data);
}

它现在每秒向 API 发送大约 3 个请求以获取积分,并且它们确实会发回一个快递员列表,但大量请求不允许快递员的 mraker(由服务响应)显示在地图。 我该怎么办?

【问题讨论】:

    标签: angular


    【解决方案1】:

    已解决:看起来它是任何使用 API 实验版本的网站

    如果您将 ?v=3 添加到 js 调用中,那么它将使用发布版本 (3.31) 而不是 (3.32)

    【讨论】:

      猜你喜欢
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多