4

I have made a drag-and-drop feature so that users can drag an icon from the sidebar and when they drop the icon, a marker is placed.

The below implementation seemed like the best (only) way to achieve it, but issues are occurring when the network is slow, presumably because the lat/lng from the mouseover event is (very) inaccurate.

Can anyone offer an alternative way I could do this? Perhaps placing the marker immediately and then using the built-in maps drag-n-drop ?

function placeMarker(lat, lng) { var marker = new google.maps.Marker({ position: new google.maps.LatLng(lat, lng), draggable: true, map: map }); return marker; } $(".icon").draggable({helper: 'clone', start: function(e, ui) { map.setOptions({draggable: false}); $("#map").css('cursor', 'crosshair'); }, stop: function(e,ui) { map.setOptions({draggable: true}); $("#map").css('cursor', 'default'); google.maps.event.addListenerOnce(map, "mouseover", function(event) { var lat = event.latLng.lat(), lng = event.latLng.lng(), id = ui.helper.context.id; pointA = id === "pointA" && pointA === true ? pointA.setMap(null) : placeMarker(lat, lng); pointB = id === "pointB" && pointB === true ? pointB.setMap(null) : placeMarker(lat, lng); }); } }); 
3
  • 1
    What are the issues that are occurring? Commented Mar 4, 2016 at 10:54
  • 1
    The marker takes long to place and when it does, it is being placed in the wrong location on the map. Commented Mar 4, 2016 at 10:58
  • maybe try use the google.maps.Geocoder() service developers.google.com/maps/documentation/javascript/geocoding Commented Mar 4, 2016 at 11:14

1 Answer 1

1

The issue is resolved when using the mousemove event instead of mouseover.

I think this is the event I should have been using all along. The low latency obviously interferes with the initial mouseover event not firing as the pin is dropped.

Hope this can help others.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.