I have a somewhat interesting problem I am having a hard time figuring out. I am implementing a draggable div from outside the map, and would like to drag it onto the map. I have gotten as far as triggering the event and grabbing the position of the drop, but now I need to translate that into something the map will understand.
Is there a way to convert the values returned by .position() into a latlng or point that google maps will understand? I have been messing with the map projections, but can’t seem to get it to work relative to the viewport on the map. Any point in the right direction would be terrific.
$('#map').droppable({
drop: function(e, ui) {
console.log(e);
console.log(ui);
var rawMouseLocation = $('#map').mapPlugin('mouseLocation', ui.position);
mouseLocation = rawMouseLocation.toString().replace(/[()]/g,'')
var field = $(ui.draggable[0]).data('fieldID');
var iconPath = $(ui.draggable[0]).find('img').attr('src');
$('.'+field).val(mouseLocation).removeClass('default-text');
var layerName = $('#map').mapPlugin('addNewFieldLayer',field, rawMouseLocation, {
"iconPath":iconPath,
'onDragEnd':self.updateField
});
newLayers.push(layerName);
$(ui.draggable).draggable( 'disable' );
}
});
Inside of the ‘mouseLocation’ function, I need a way to convert that position into the map coordinates. I am not even sure this is possible, but any help would be greatly appreciated. Thanks.
I was able to come up with a solution which uses the map overlayView.
and then in my mouseLocation function, I do this:
which has the latlng of the mouse location! Thanks! @Vesliq