我正在尝试构建一个Angula2应用程序,当我点击地图中的某个点以便能够在我的数据库中插入这些字段时,我想得到位置(经度和纬度)。 这是地图代码:
<sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" [backgroundColor]="backgroundColor" >
<sebm-google-map-marker *ngFor=" let post of posts" [latitude]="post.lapti" [longitude]="post.longi" ></sebm-google-map-marker>
</sebm-google-map>
任何解决方案?
答案 0 :(得分:2)
您有mapclick事件:
<sebm-google-map (mapClick)="getPosition($event)" [latitude]="lat" [longitude]="lng" [zoom]="zoom" [backgroundColor]="backgroundColor" >
<sebm-google-map-marker *ngFor=" let post of posts" [latitude]="post.lapti" [longitude]="post.longi" ></sebm-google-map-marker>
</sebm-google-map>
...
getPosition(event: MouseEvent ) {
let coords: LatLngLiteral = event.coords; //coords.lat, coords.lng are numbers
console.log(coords.lat); //the clicked point latitude
console.log(coords.lng); //the clicked point longitude
...
}
此处的Plunker:http://plnkr.co/edit/UWl3Tm