Rodimell Vasquez
Rodimell Vasquez

Reputation: 13

Google Appmaker MAP api draggable marker and save new coordinates

I am currently working on a project using Google App maker and I have came across the google map API Draggable Marker question posted here.

I was wondering how to save the coordinates of the marker when I drag it along the map.

I have tried the code below but it saves the coordinates of the center of the map not the marker. i've put a sample picture of what im planning to do.

var marker = widget.getAddressMarkerJs();
marker.setDraggable(true);

record.latitude = widget.latitude();
record.longtitude = widget.longitude();                

UPDATE** This is my code now (an abomination >__<)

var marker = widget.getAddressMarkerJs();
marker.setDraggable(true);

marker.addListener('dragend', function (event) {
var latLng = event.latLng;
var ds = app.datasources.Nomination;
ds.item.latitude = latLng.lat();
ds.item.longtitude = latLng.lng();

});   

Upvotes: 1

Views: 173

Answers (1)

Pavel Shkleinik
Pavel Shkleinik

Reputation: 6347

Google Maps API lets you add event listener to the marker and it seems that the most suitable for your case is dragend one:

// Map's onAttach event handler
var marker = widget.getAddressMarkerJs();
marker.setDraggable(true);

marker.addListener('dragend', function (event) {
  var latLng = event.latLng;
  console.log(latLng.lat(), latLng.lng());
});

Upvotes: 1

Related Questions