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: 799
  • jGoogleMaps.zip
    147.5 KB · Views: 500
Last edited:

rboeck

Well-Known Member
Licensed User
Sorry for the problems; now i get

B4X:
Error description: Property: Position is writeonly.
Occurred on line: 325
    Dim Point As LatLng = K(i).M.Position

it worked with all previous versions.
 

rboeck

Well-Known Member
Licensed 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
Marker .remove and .label no longer exists.
Can we also have the latest version that supports them ?
George
 

Pedro Caldeira

Active Member
Licensed 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
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
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
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 ....
 

magi6162

Well-Known Member
Licensed User
there is an event like "clickPolygon" to select a polygon? Can the selected polygon change it (move nodes, etc ..)?
 
Status
Not open for further replies.
Top