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: http://rterp.github.io/GMapsFX/
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.

v1.10 - New AddPolyline method.

Example:
B4X:
Dim l1, l2, l3 As LatLng
l1.Initialize(20, 20)
l2.Initialize(25, 25)
l3.Initialize(30, 20)
gmap.AddPolyline(Array (l1, l2, l3), 4, fx.Colors.Red)

v1.20 - New AddPolygon method.

v1.21 - Fixes a crash that happens after clicking on the Google link. Note that it will cause the map to reset.

V1.50 - Based on the latest version of GMapsFX. New Initialize2 method allows setting the API key:
https://developers.google.com/maps/documentation/javascript/get-api-key#key

V1.55 - Reapplied most of the changes done by Informatix in v1.28.

V1.61 - Fixes an issue related to the API key.

V1.62 - Removed the new full screen control (which doesn't do anything in desktop apps).
V1.65 - Adds PolylineClick (SelectedPolyline As MapPolyline) event.
V1.70 - Fixes the font issue on Macs.
V1.71 - Fixes an issue with MapCircle.Radius.
V1.75 - Polygons, Polylines and Circles are only clickable if the relevant click event is handled.
V1.80 - Adds compatibility with B4JPackager11. You need to set AdditionalModuleInfoString to "exports com.lynden.gmapsfx.javascript.event;"
V1.81 - Marker.Position property is read / write property (was write only).
V1.82 - Changes the way the map is loaded internally as the previous method no longer works.

Note that due to a bug in the native WebView the map can disappear if the user drags it too fast. For that reason it is important to show a "reset map" button that resets its position.

The map will not work properly without an API key.

If you are using Java 9 then you need to call Form.Show before adding the map (https://www.b4x.com/android/forum/threads/java-9-and-webview-and-googlemaps.85353/).
 

Attachments

  • GoogleMapsExample.zip
    2.7 KB · Views: 804
  • jGoogleMaps.zip
    147.5 KB · Views: 508
Last edited:

klaus

Expert
Licensed 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

Well-Known Member
Licensed 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: 294

marcick

Well-Known Member
Licensed User
I remember similar problems when the API_KEY was wrong or undeclared. Did you check it ?
 
Status
Not open for further replies.
Top