B4J Question jGoogleMaps - Drag/Drop Marker Events

RichardN

Well-Known Member
Licensed User
Longtime User
The jGoogleMaps library does not expose marker drag or drop events.

Has anyone found a smart workaround for this perhaps using the Marker click event or mouse events or something else?
 

TILogistic

Expert
Licensed User
Longtime User
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
mouse event
B4X:
    Dim jo As JavaObject = gmap
    Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "MouseMove", Null)
    jo.GetFieldJO("map").RunMethod("addUIEventHandler", Array("mousemove", event))

B4X:
Sub MouseMove_Event (MethodName As String, Args() As Object) As Object
    Dim jo As JavaObject = Args(0)
    jo = jo.RunMethod("getMember", Array("latLng"))
    Dim ll As LatLng = jo.InitializeNewInstance("com.lynden.gmapsfx.javascript.object.LatLong", Array(jo))
    Log( ll.Latitude & "," & ll.Longitude)
    Return Null
End Sub
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
@TILogistic

Sorry for the delay.... I have been testing a few ideas around your code above. A constantly updated LL position is very useful if you can compare it to the previous marker position. Sadly without a working MouseUp event associated with map, map-pane or marker, then capturing the new marker position remains elusive.

I suppose I could run a timer sampling the Marker position but that's rather messy.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
events on the map
B4X:
    Dim jo As JavaObject = gMap
    Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "MouseMove", Null)
    jo.GetFieldJO("map").RunMethod("addUIEventHandler", Array("mousemove", event))
    
    Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "MouseUp", Null)
    jo.GetFieldJO("map").RunMethod("addUIEventHandler", Array("mouseup", event))
    
    Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "MouseDown", Null)
    jo.GetFieldJO("map").RunMethod("addUIEventHandler", Array("mousedown", event))
    
    Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "RightClick", Null)
    jo.GetFieldJO("map").RunMethod("addUIEventHandler", Array("rightclick", event))
    
    
    Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "MouseOut", Null)
    jo.GetFieldJO("map").RunMethod("addUIEventHandler", Array("mouseout", event))
    
    
    Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "Dblclick", Null)
    jo.GetFieldJO("map").RunMethod("addUIEventHandler", Array("dblclick", event))
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
events:
1689415798470.png

1689416347005.png
 
Last edited:
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
@TILogistic .....

I can reproduce the map events just fine but I am failing with the marker DragEnd event. There is something wrong with this code where the event is not in the collection. I am missing something basic here.....

B4X:
Dim jo As JavaObject = ThisMarker
jo.GetFieldJO("jsObject").RunMethod("eval", Array($"this.setOptions({draggable: true});"$))
        
Dim event As Object = jo.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "DragEnd", Null)
jo.GetFieldJO("marker").RunMethod("addUIEventHandler", Array("dragend", event))


Sub DragEnd_Event (MethodName As String, Args() As Object) As Object
    
    Log("Drag End Event Fired")
    Return Null
    
End Sub
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
@TILogistic

You have quoted several references and examples in Java of how to access map-marker mouse events. You have also posted very comprehensive Google Maps examples to the forum where you have made extensive use of the Java Object method to expose events. I note however that none of you examples includes code to demonstrate JO calls to the jGoogleMaps library for the Marker events... dragstart, drag and dragend.

Is it possible that @Erel in his initial observation was correct in saying that access to these events is far from being a simple matter?

If you would like to post an example of a listener and event handler for Google Maps marker mouse events in B4J I know we would all be interested.
 
Upvote 0
Top