B4J Library jGoogleMaps library

Status
Not open for further replies.
This library is similar to B4A and B4i GoogleMaps libraries.

SS-2015-07-30_15.35.52.jpg


It is based on this open source project: https://github.com/dlsc-software-consulting-gmbh/GMapsFX/ (Apache 2 license).
Under the hood it uses JavaFX WebView with GoogleMaps JavaScript API V3.

Using the map is quite simple. You need to initialize GoogleMap and then wait for the Ready event.
GoogleMap.AsPane returns the pane that holds the map. You should add this pane to the nodes tree.

Once the ready event is fired you can add markers or change the position.

Updates:

V2.01 - Sets the Google Maps Javascript SDK version to 3.56. There is currently an issue with JavaFX and Google Maps v3.57. A big thank you to @Star-Dust for helping with solving this issue!
V2.00 - Depends on OpenJDK 19. Previous versions will not work.

1. OpenJDK 19.0.2 + OpenJFX 17.0.6: https://www.b4x.com/b4j/files/jdk-19.0.2.7z
2. Add to main module:
B4X:
#PackagerProperty: IncludedModules = javafx.web
#PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx;    exports com.lynden.gmapsfx.javascript;    exports com.lynden.gmapsfx.javascript.event;
#PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx.javascript.object;    exports com.lynden.gmapsfx.service.directions;    exports com.lynden.gmapsfx.service.elevation;
#PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx.service.geocoding;    exports com.lynden.gmapsfx.shapes;    exports com.lynden.gmapsfx.zoom;
3. Add reference to jOkHttpUtils2.

Tip: to fix logging encoding issues with Java 19+, add this:
B4X:
#VirtualMachineArgs: -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8
#PackagerProperty: VMArgs = -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8

The standalone package will not work without steps 2 and 3.
 

Attachments

  • GoogleMapExample.zip
    2.8 KB · Views: 426
  • jGoogleMaps.zip
    199.3 KB · Views: 206
Last edited:

jmon

Well-Known Member
Licensed User
Longtime User
{Following previous message}
I also get this error when resizing the window with no internet connection (that one crashes my app):
java.lang.NullPointerException
at com.lynden.gmapsfx.GoogleMapView.mapResized(GoogleMapView.java:121)
at com.lynden.gmapsfx.GoogleMapView.lambda$2(GoogleMapView.java:83)
at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property.ReadOnlyDoubleWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyDoubleWrapper.java:177)
at javafx.beans.property.ReadOnlyDoubleWrapper.fireValueChangedEvent(ReadOnlyDoubleWrapper.java:143)
at javafx.beans.property.DoublePropertyBase.markInvalid(DoublePropertyBase.java:113)
at javafx.beans.property.DoublePropertyBase.set(DoublePropertyBase.java:147)
at javafx.scene.web.WebView.resize(WebView.java:303)
at javafx.scene.Node.resizeRelocate(Node.java:2941)
at javafx.scene.layout.AnchorPane.layoutChildren(AnchorPane.java:363)
at javafx.scene.Parent.layout(Parent.java:1079)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Parent.layout(Parent.java:1085)
at javafx.scene.Scene.doLayoutPass(Scene.java:552)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2397)
at com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:381)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:510)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:490)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$404(QuantumToolkit.java:319)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

This error can be reproduced (in the example) if you have no internet connection when starting. It will crash the app directly.
You can try catch the error and it won't crash the app like this:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    '...
    Try
        Dim options As MapOptions
        options.StreetViewControl = False
        gmap.Initialize("gmap", options)
        Pane1.AddNode(gmap.AsPane, 0, 0, Pane1.Width, Pane1.Height) 
    Catch
        '...
    End Try 
End Sub

Sub Pane1_Resize (Width As Double, Height As Double)
    Try
        gmap.AsPane.SetSize(Width, Height)
    Catch
        '...
    End Try
End Sub
but it shows a list of errors like the one above.

Thank you.

[Edit] edited the post with instructions on how to reproduce the bug
 
Last edited:

MichalK73

Well-Known Member
Licensed User
Longtime User
When my application is running behind a proxy server, the map does not appear. In a network without a proxy it is functioning properly. Can it be set to work behind a proxy server?
 

MichalK73

Well-Known Member
Licensed User
Longtime User
ok. I managed to connect to the proxy, but still does not display. Wine after the company administrator, blocked because the security policy of the company.

Thanks a lot.
 

Pere Vinyes

Member
Licensed User
Longtime User
This code works fine and shows the red google icon:
M=gmap.AddMarker(posx,posy,"Label")

But this code is not showing any icon on map. Do you know why?

file= "C:\x\icon1.png"
M=gmap.AddMarker2(posx,posy,"Label",file)

icon1 exists and is a simplification of file=File.GetUri( File.DirApp & "\icons\" , "icon1.png")

Thanks a lot
 

Pere Vinyes

Member
Licensed User
Longtime User
With the documentation available I can't fix it. And I read almost all B4J blog.

Again, with:
file= "C:\x\icon1.png"
M=gmap.AddMarker2(posx,posy,"Label",file)

with this two simple sentences the map is not showing the Icon and I think there are some library bug over there.

Could you please check it or supply and example?

thanks and kind regards.
 

Pere Vinyes

Member
Licensed User
Longtime User
I already read this information, Erel. It may work in B4A but not in B4J. (or where is the "DirAssets" directory location in B4J?)

Thanks "rboeck" for your answer but still does not work ... the red standard Google icon appears.

Someone has tried?

file= File.GetUri("c:\x","icon1.png")
M=gmap.AddMarker2(posx,posy,"Label",file)
 

rboeck

Well-Known Member
Licensed User
Longtime User
My mistake was, to think that other directories are also useable; i for myself used File.DirAssets. I made i working sample for you.
 

Attachments

  • Demo.zip
    3.1 KB · Views: 516

jmon

Well-Known Member
Licensed User
Longtime User
Did you set the proxy in Windows internet options?

This solution won't work if you are not already connected to internet on that computer. Basically it doesn't bridge your connection to the proxy directly.
 

Informatix

Expert
Licensed User
Longtime User
It's fixed. I had to add also the settings for https.
B4X:
SetSystemProperty("http.proxyHost", "10xxxx")
SetSystemProperty("http.proxyPort", "3xxxx")
SetSystemProperty("https.proxyHost", "10xxxxxx")
SetSystemProperty("https.proxyPort", "3xxxx")
SetSystemProperty("java.net.useSystemProxies", "False")
 
Status
Not open for further replies.
Top