在地图上拖动原始标记时,我试图检索坐标(如纬度和经度)。
我试图实现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);
}
}发布于 2019-09-06 10:08:34
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);
}希望它也能帮到别人..。
发布于 2019-09-06 07:24:14
您需要在ts文件中执行类似的操作:
markerDragEnd($event: MouseEvent): void {
this.markerCreator($event, '');
}
markerCreator($event: any): void {
console.log($event.coords.lat)
console.log($event.coords.lng)
}<agm-marker
[markerDraggable]="newMarker.draggable"
(dragEnd)="markerDragEnd($event)"
></agm-marker>https://stackoverflow.com/questions/57817406
复制相似问题