当原点标记在 map 上拖动时,我试图检索纬度和经度等坐标。
我尝试实现 Dragend 或 Dragend 属性,但没有任何效果
html
<agm-map id="map" [latitude]='origin.lat' [longitude]='origin.lng' [zoom]='zoom'>
<agm-direction [origin]="origin" [destination]="destination" [renderOptions]="renderOptions" [markerOptions]="markerOptions" (dragEnded)="getcoords($event)"></agm-direction>
</agm-map>
ts 文件
import { Component } from '@angular/core';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { ViewChild, ElementRef, NgZone } from '@angular/core';
import { MapsAPILoader, AgmMap } from '@agm/core';
import {} from "googlemaps";
declare let google: any;
@Component({
selector: 'app-root',
templateUrl: './direction.component.html',
styleUrls: ['./app.component.css'],
})
export class AppDirection
{
public origin: {};
public destination: {};
public renderOptions = {
suppressMarkers: true,
}
public markerOptions = {
origin: {
draggable: true,
},
destination: {
opacity: 0.8,
},
}
origin={lat:30.7227148,lng:76.6932551};
destination={lat:30.7123702,lng:76.71970320000003};
constructor(private mapsAPILoader: MapsAPILoader, private ngZone: NgZone){}
ngOnInit() {}
getcoords(event){
console.log(event);
}
}
最佳答案
originDrag 是检索 <agm-direction>
中原点变化时的纬度和经度的函数下面是对我有用的代码:
html 代码:
<agm-direction [origin]="origin" [destination]="destination" [renderOptions]="renderOptions" [markerOptions]="markerOptions" (originDrag)="getcoords('direction',$event)"> </agm-direction>
在 ts 文件中:
getcoords(type,event)
{
let coords=JSON.stringify(event);
let coords3=JSON.parse(coords);
console.log("updated latitude :: "+coords3.lat);
console.log("updated longitude :: "+coords3.lng);
}
希望它也能帮助其他人......
关于angular - 在 <agm-direction> 中拖动原点时方向发生变化时获取坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57817406/