【发布时间】:2017-08-09 12:22:48
【问题描述】:
我正在使用 Agm 在地图上显示位置,到目前为止它运行良好,但现在我还需要显示方向,例如在导航期间连接地图中两个点的那条线,我查看了文档,但它不是显示很多。
谢谢你
【问题讨论】:
我正在使用 Agm 在地图上显示位置,到目前为止它运行良好,但现在我还需要显示方向,例如在导航期间连接地图中两个点的那条线,我查看了文档,但它不是显示很多。
谢谢你
【问题讨论】:
agm-direction 可以帮到你
step.1 安装agm
npm install --save @agm/core
step.2 安装 agm-direction
npm install --save agm-direction
step.3 导入模块
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AgmCoreModule } from '@agm/core';
import { AgmDirectionModule } from 'agm-direction';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AgmCoreModule.forRoot({ // @agm/core
apiKey: 'your key',
}),
AgmDirectionModule // agm-direction
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
step.4 html
<agm-map [latitude]="lat" [longitude]="lng">
<agm-direction *ngIf="dir" [origin]="dir.origin" [destination]="dir.destination"></agm-direction>
</agm-map>
step.5 打字稿
lat: Number = 24.799448;
lng: Number = 120.979021;
zoom: Number = 14;
dir = undefined;
public getDirection() {
this.dir = {
origin: { lat: 24.799448, lng: 120.979021 },
destination: { lat: 24.799524, lng: 120.975017 }
}
}
属性
【讨论】: