使用 Angular google 地图获取地图的西北和东南 (AGM)
Get NorthWest and SouthEast of a map with Angular google maps (AGM)
现在 Angular google 地图给我们 boundsChange
事件,每次地图边界改变时都会触发该事件。如果我们说边界是一个矩形或一个盒子,那么我将需要 4 个点来表示那个盒子。活动只给我们东北点和西南点,我应该怎么得到另外两个点?
<agm-map #map [latitude]="lat" [longitude]="lng"
[zoom]="zoom" [mapTypeId]="mapTypeId" (boundsChange)="onBoundsChange($event)" [fitBounds]="true">
</agm-map>
onBoundsChange(bounds: LatLngBounds) {
let NorthEst = bounds.getNorthEast().toJSON();
let SouthWst = bounds.getSouthWest().tpJSON();
// No Function to get NorthWest and SouthEast!
}
我们可以这样从给定的点中得出其他点:
let NorthWest: any = [bounds.getNorthEast().lng(), bounds.getSouthWest().lat()];
let SouthEst: any = [bounds.getSouthWest().lng(), bounds.getNorthEast().lat()];
这是一个简单的数学技巧,它完成了工作。
现在 Angular google 地图给我们 boundsChange
事件,每次地图边界改变时都会触发该事件。如果我们说边界是一个矩形或一个盒子,那么我将需要 4 个点来表示那个盒子。活动只给我们东北点和西南点,我应该怎么得到另外两个点?
<agm-map #map [latitude]="lat" [longitude]="lng"
[zoom]="zoom" [mapTypeId]="mapTypeId" (boundsChange)="onBoundsChange($event)" [fitBounds]="true">
</agm-map>
onBoundsChange(bounds: LatLngBounds) {
let NorthEst = bounds.getNorthEast().toJSON();
let SouthWst = bounds.getSouthWest().tpJSON();
// No Function to get NorthWest and SouthEast!
}
我们可以这样从给定的点中得出其他点:
let NorthWest: any = [bounds.getNorthEast().lng(), bounds.getSouthWest().lat()];
let SouthEst: any = [bounds.getSouthWest().lng(), bounds.getNorthEast().lat()];
这是一个简单的数学技巧,它完成了工作。