首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在<agm-方向上沿原点拖动改变方向时获得坐标

在<agm-方向上沿原点拖动改变方向时获得坐标
EN

Stack Overflow用户
提问于 2019-09-06 07:17:48
回答 2查看 2K关注 0票数 2

在地图上拖动原始标记时,我试图检索坐标(如纬度和经度)。

我试图实现dragend或dragend属性,但是没有任何效果。

html

代码语言:javascript
运行
复制
<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文件

代码语言:javascript
运行
复制
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);
 }  
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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文件中:

代码语言:javascript
运行
复制
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);
    }

希望它也能帮到别人..。

票数 2
EN

Stack Overflow用户

发布于 2019-09-06 07:24:14

您需要在ts文件中执行类似的操作:

代码语言:javascript
运行
复制
    markerDragEnd($event: MouseEvent): void {
        this.markerCreator($event, '');
    }

   markerCreator($event: any): void {
     console.log($event.coords.lat)
     console.log($event.coords.lng)
   }

代码语言:javascript
运行
复制
<agm-marker
  [markerDraggable]="newMarker.draggable"
  (dragEnd)="markerDragEnd($event)"
></agm-marker>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57817406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档