How to Update the Location of a Marker When it is Moved

Description

The latitude and longitude value in the current Grid row can be updated when the user drags the marker to a new position on the map.

Discussion

The latitude and longitude values of a marker can be updated when the marker for a map in a Grid component is moved. The "Marker can be dragged to a new location" property enables an event that is called when a marker is moved, the "OnMarkerDragComplete" event.

You can define a javascript method to capture the new marker location when a Marker is moved that will be called when the OnMarkerDragComplete event is fired. The new latitude and longitude values for the marker will be passed to the function. The function takes two parameters: a pointer to the Google Maps 'Marker' object and an object with the row number for the marker that was moved.

These two parameters can be used to update the marker's record in the Grid component. For example:

function onMarkerDrop (m, e) {
     // m - pointer to the Google Maps 'Marker' object
     // e - contains e.rowNumber, the row number for the marker that was dragged

     var lat = m.position.lat();
     var lng = m.position.lng();

     {grid.object}.setValue('G','latitude',e.rowNumber,lat);
     {grid.object}.setValue('G','longitude',e.rowNumber,lng);
}

For full details and step-by-step instructions, watch this video: