Angular-google-maps: How about 2-way binding on marker lat/lng?

Created on 7 Jul 2017  ·  4Comments  ·  Source: SebastianM/angular-google-maps

(read title)
P.S. exportAs: 'agmMarker'

stale

Most helpful comment

@matt-lethargic Smth like this:
<agm-marker [markerDraggable]="true" (dragEnd)="markerMoved($event)" [latitude]="latitude || 39.8282" [longitude]="longitude || -98.5795"></agm-marker>

markerMoved(e) { const geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': e.coords}, (res, status) => { if (status === google.maps.GeocoderStatus.OK && res.length) { this.ngZone.run(() => this.setLocation(res[0])); } }) }

setLocation(place) { this.latitude = place.geometry.location.lat(); this.longitude = place.geometry.location.lng(); }

All 4 comments

I'm new to Angular2 and AGM, but I would love this, really thought it would have been in already.
Does anyone know how to get the lat/lng from a dragged marker??

@matt-lethargic Smth like this:
<agm-marker [markerDraggable]="true" (dragEnd)="markerMoved($event)" [latitude]="latitude || 39.8282" [longitude]="longitude || -98.5795"></agm-marker>

markerMoved(e) { const geocoder = new google.maps.Geocoder(); geocoder.geocode({'location': e.coords}, (res, status) => { if (status === google.maps.GeocoderStatus.OK && res.length) { this.ngZone.run(() => this.setLocation(res[0])); } }) }

setLocation(place) { this.latitude = place.geometry.location.lat(); this.longitude = place.geometry.location.lng(); }

<agm-marker (dragEnd)="draggEnded($event)" [markerDraggable]="true" [latitude]="tripMirror.departure?.latitude" [longitude]="tripMirror.departure?.longitude" iconUrl="assets/icons/icon_marker_red.png"></agm-marker>

For some reason when I try to drag it I only move the entire map, I'm not able to move the marker...any help on this?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nthonymiller picture nthonymiller  ·  4Comments

DeveloperAdd007 picture DeveloperAdd007  ·  3Comments

n1t3w0lf picture n1t3w0lf  ·  3Comments

PeterSisovsky picture PeterSisovsky  ·  3Comments

gnujeremie picture gnujeremie  ·  3Comments