【发布时间】: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