From dedcf2a0a8e42c37a32e093b64609ebb70f036ff Mon Sep 17 00:00:00 2001 From: Manoj Date: Thu, 2 Mar 2017 00:02:18 +0530 Subject: [PATCH] additional option added which allows marker to be moved via click on the map --- src/locationpicker.jquery.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/locationpicker.jquery.js b/src/locationpicker.jquery.js index 9c613ae..206df08 100644 --- a/src/locationpicker.jquery.js +++ b/src/locationpicker.jquery.js @@ -423,6 +423,19 @@ google.maps.event.addListener(gmapContext.marker, "dragend", function(event) { displayMarkerWithSelectedArea(); }); + google.maps.event.addListener(gmapContext.map, "click", function(event) { + if(gmapContext.settings.clickToMoveMarker) { + // Below code is to prevent intereference with double-clicks i.e. double clicks will not move marker + mapZoom = gmapContext.map.getZoom(); + setTimeout(function() { + if(gmapContext.map.getZoom() == mapZoom) { + gmapContext.marker.setPosition(event.latLng); + updateInputValues(gmapContext.settings.inputBinding, gmapContext); + displayMarkerWithSelectedArea(); + } + }, 200); + } + }); GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context){ updateInputValues(settings.inputBinding, gmapContext); // Set input bindings if needed @@ -458,6 +471,7 @@ // must be undefined to use the default gMaps marker markerIcon: undefined, markerDraggable: true, - markerVisible : true + markerVisible : true, + clickToMoveMarker : false } }( jQuery ));