Angular5 |XHR完成加载:持续运行 [英] Angular5 | XHR finished loading: GET "<URL>" keeps running

查看:67
本文介绍了Angular5 |XHR完成加载:持续运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an angular 5 application with supported by an api that provides a list of nearby couriers (taxi drivers) for of the selected marker location. Everything was working perfectly until today that it seems like it keeps requesting for the couriers' locations from an api. the request is made from a method in a service.

有人遇到过这个问题吗?

Anyone facing this issue before?

组件:

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(由服务响应)地图.我应该怎么办?

It is now sending approximately 3 requests per second to the API to get points and they do send back a list of couriers but the high number of requests do not allow the couriers' mrakers (responsed by the service) to be displayed on the map. What am i supposed to do with this?

推荐答案

已解决:看起来像是使用该API实验版本的任何站点

SOLVED: Looks like it's any site using the experimental version of the API

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

If you add ?v=3 to the js call then it will use the release version (3.31) instead of (3.32)

这篇关于Angular5 |XHR完成加载:持续运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆