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.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

  • jGoogleMaps.zip
    199.5 KB · Views: 385
  • GoogleMapExample.zip
    2.8 KB · Views: 253
Last edited:

rboeck

Well-Known Member
Licensed User
Longtime User
It's not possible, to write this code:
Dim Point as Latlng
Point.Latitude=12 (Property: Latitude is readonly)

In B4A and i think in all older versions of jgooglemaps.jar it was possible.
 

gvoulg

Member
Licensed User
Longtime User
Marker .remove and .label no longer exists.
Can we also have the latest version that supports them ?
George
 

Pedro Caldeira

Active Member
Licensed User
Longtime User
I Get an error just by running the example, after a few seconds I get the following Error.

B4X:
Waiting for debugger to connect...
Program started.
Error occurred on line: 64 (Main)
java.lang.NullPointerException
    at com.lynden.gmapsfx.javascript.object.GoogleMap.internalGetZoom(GoogleMap.java:76)
    at com.lynden.gmapsfx.javascript.object.GoogleMap.zoomProperty(GoogleMap.java:93)
    at com.lynden.gmapsfx.javascript.object.GoogleMap.setZoom(GoogleMap.java:68)
    at anywheresoftware.b4j.objects.GoogleMapWrapper.MoveCamera(GoogleMapWrapper.java:219)
    at b4j.google.map.main._btnresetmap_action(main.java:161)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:226)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA$2.run(BA.java:165)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    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)
 

Matias Ferrer

Member
Licensed User
Longtime User
Hello everyone.

I have a problem with jGoogleMaps with my application and also with the example application of the library.

After running the application, I wait for 5 seconds and the following error message appears:

"Oops! Something went wrong.

This page did not load Google Maps correctly. See the JavaScript console for technical details. "

Error-GoogleMaps.png


I have updated the version of jGoogleMaps to 1.55 and my version of java to 1.8.0.121.
The error continues

Someone can help me.


Thank you!
 

bvonlaar

Member
Licensed User
Longtime User
You can use this code:
B4X:
Sub SetMarkerLabel(m As Marker, text As String)
   Dim r As Reflector 'jReflection library
   r.Target = m
   r.RunMethod4("invokeJavascript", Array("setLabel", Array(text)), Array As String("java.lang.String", "[Ljava.lang.Object;"))
End Sub

Hi,
it works fine, but how can I change the color of the "text"

Benedikt
 

marcick

Well-Known Member
Licensed User
Longtime User
I was reading in poste 72

- I added the AddMarker3 function, which allows to specify an origin and an anchor position for the marker icon

But I understand the method has then been removed for some reasons.
So ... this is still a wish ....
 

klaus

Expert
Licensed User
Longtime User
there is an event like "clickPolygon" to select a polygon? Can the selected polygon change it (move nodes, etc ..)?
Yes.
You have the PolygonClick event when the user clicks on a polygon.
Then you can set it editable and / or draggable with the JavaObjects library.
Same for polyline and circle.
B4X:
Private Sub GMap_PolygonClick (SelectedPolygon As MapPolygon)
    Private joMapPolygon = SelectedPolygon As JavaObject
    joMapPolygon.RunMethod("setEditable", Array As Object(True))
    joMapPolygon.RunMethod("setDraggable", Array As Object(True))

You can also add a MouseMove event, look HERE.
 
Last edited:

ivanomonti

Expert
Licensed User
Longtime User
error

B4X:
Waiting for debugger to connect...
Program started.
Errore nella linea: 188 (Main)
java.lang.NullPointerException
    at anywheresoftware.b4j.objects.GoogleMapWrapper.setMapType(GoogleMapWrapper.java:646)
    at b4j.example.main._listview1_selectedindexchanged(main.java:1511)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.BA$1.run(BA.java:215)
    at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
    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$149(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)

B4X:
    googlemap.MapType = googlemap.MAP_TYPE_SATELLITE
    Dim cp As CameraPosition
    cp.Initialize(45.622065, 9.1053143, 18)
    googlemap.MoveCamera(cp)
 

Attachments

  • 2018-04-10_100004.png
    2018-04-10_100004.png
    12.3 KB · Views: 504
Status
Not open for further replies.
Top