【发布时间】:2018-11-26 14:53:24
【问题描述】:
我目前正在我的应用中制作地图。我为此使用了惊人的 Angular agm 包。
目标是显示带有标记的地图。这些标记来自数据库并包含纬度和经度值。我有数百个标记,我想过滤它们。我只想显示距离我所在位置 5 公里以内的标记。我该怎么做?我浏览了包的 API 文档,但没有看到解决方案。谁能帮帮我?
Map.component.html
<!-- this creates a google map on the page with the given lat/lng from -->
<!-- the component as the initial center of the map: -->
<agm-map
[latitude]="lat"
[longitude]="lng"
[fullscreenControl]="true"
[zoom]="13"
>
<agm-marker
*ngFor="let marker of markers"
[latitude]="marker.latitude"
[longitude]="marker.longitude"
(markerClick)="doSomething($event)"
>
<agm-info-window [disableAutoPan]="true">
<a routerLink="/">Go there</a>
</agm-info-window>
</agm-marker>
</agm-map>
map.component.ts
export class FindLocalsComponent implements OnInit{
lat:number;
lng: number;
markers = [];
constructor(private findLocalsService: FindLocalsService){}
ngOnInit(){
let token = localStorage.getItem('token');
this.findLocalsService.getLocations(token)
.subscribe((data) => {
console.log(data.obj);
this.lat = data.obj.myLocation[0].latitude;
this.lng = data.obj.myLocation[0].longitude;
this.markers = data.obj.locationCollection;
})
}
}
【问题讨论】:
标签: angular google-maps