I'd like to drag an object into my Google Map (API V3) from outside the map.
After some research, I found this very helpful post and I tried to adapt it to my project.
The main idea is to drag a .png image on the map and when the mouse button is down, get the actual coordinates and place a marker at that lat / lng.
But I noticed there is a difference between the point you drag your image and the point where your marker is placed. The difference is around 10 / 15 pixels on the sample linked above, regardless the zoom level. At max zoom, it's not very important, but the more you unzoom, the more the gap is important.
Illustration of the gap :
(we are at 100 kms / 60 miles of the wanted place...)
So, why such a gap ? In the sample I linked above, the gap is less important, but it also exists. There are no error in my browser's console, and it doesn't seem to be a tricky CSS problem.
Do someone knows how to correct this problem ?
Thank you
someone or something that is unpleasant and boring: Waiting in a doctor's office is such a drag!
A force acting on a moving body, opposite in direction to the movement of the body, caused by the interaction of the body and the medium it moves through. The strength of drag usually depends on the velocity of the body.
Drag is where individuals dress up as a different gender, primarily for short periods of time, which differentiates the practice from people who are trans and change their gender socially and/or legally.
The calculation of the marker-position is not exact.
Fixed function:
$(document).ready(function() {
$("#draggable").draggable({helper: 'clone',
stop: function(e,ui) {
var mOffset=$($map.getDiv()).offset();
var point=new google.maps.Point(
ui.offset.left-mOffset.left+(ui.helper.width()/2),
ui.offset.top-mOffset.top+(ui.helper.height())
);
var ll=overlay.getProjection().fromContainerPixelToLatLng(point);
placeMarker(ll);
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With