Angular5 | XHR完成加载:GET“ “继续跑步

问题描述 投票:0回答:1

我有一个角度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个请求以获得积分,并且它们确实发送回一个快递列表,但是大量请求不允许快递员的mrakers(由服务响应)显示在地图上。我应该怎么做呢?

angular
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.