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

matishw picture matishw  路  3Comments

Subhojit1992 picture Subhojit1992  路  3Comments

nthonymiller picture nthonymiller  路  4Comments

maneesht picture maneesht  路  3Comments

dineshkumar20 picture dineshkumar20  路  3Comments