【问题标题】:How to create a agm-direction with multiples points?如何创建具有多个点的 agm 方向?
【发布时间】:2019-10-22 05:23:27
【问题描述】:

我有 10 个点(西部和南部 cood),我需要用这些点创建一个 unic agm-map。路线必须经过所有这些点。但是....当我搜索时,我找到了起点和终点。但是……还有中间点?

 <agm-direction *ngIf="dir" [origin]="dir.origin" [destination]="dir.destination"></agm-direction>

我正在使用 Angular 7。还有 npm agm 地图

【问题讨论】:

    标签: angular google-maps google-maps-api-3 maps


    【解决方案1】:

    您正在寻找的是 Google Maps Directions Service API 中的航点,其中:

    允许您计算通过其他位置的路线,其中 如果返回的路线通过给定的航路点。

    waypoint 包含以下字段:

    • location(必填)指定航路点的地址。
    • stopover(可选)指示此航路点是路线上的实际停靠点(真)还是只是路线的偏好
      通过指示的位置 (false)。中途停留是真实的
      默认。

    我猜你正在使用Agm-Direction component 来绘制路线,如果是这样,可以像这样指定航点:

    <agm-map [latitude]="lat" [longitude]="lng">
      <agm-direction [origin]="origin" [destination]="destination" [waypoints]="waypoints"></agm-direction>
    </agm-map>
    
    
    export class AppComponent {
    
      lat = 41.85;
      lng = -87.65;
    
      origin = { lat: 29.8174782, lng: -95.6814757 };
      destination = { lat: 40.6976637, lng: -74.119764 };
      waypoints = [
         {location: { lat: 39.0921167, lng: -94.8559005 }},
         {location: { lat: 41.8339037, lng: -87.8720468 }}
      ];
    }
    

    Here is a demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 2015-10-06
      相关资源
      最近更新 更多