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:

Informatix

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

rbghongade

Active Member
Licensed User
Dear friends,
Is it possible to display the marker label continuously? Say I want to display the temperature associated with a marker which gets updated on new data. Currently the marker label is displayed only when we have a mouse over action.

Got the solution:
As indicated in previous posts by Erel and others, I used a sub called "ShowInfoWindow".
But now the new label gets created on top of the old one , instead of replacing it. Any suggestion to resolve this problem?
 
Last edited:

Informatix

Expert
Licensed User
Here's the version 1.26 of jGoogleMaps:
- I fixed the bug of the event name (upper or mixed case is now allowed);
- I added the LatLongBounds class;
- I added Bounds, FitBounds, PanToBounds, IsReady, RemovePolyline, RemovePolygon, Zoom.
 

Attachments

  • jGoogleMaps_1_26.zip
    248 KB · Views: 359

rboeck

Well-Known Member
Licensed User
Do you have some information or examples how to use the new possibilities. I have tried to use googlemapsextras to use LatLngBoundsBuilder, but i think it is only useable with android. So we have to find out the borders by an own subroutine or are there any other possibities?
 

Informatix

Expert
Licensed User
Do you have some information or examples how to use the new possibilities.
All functions are documented.
Example for FitBounds:
B4X:
Dim NE, SW As LatLng
NE.Initialize(MaxLatitude, MaxLongitude)
SW.Initialize(MinLatitude, MinLongitude)
MyBounds.Initialize(NE, SW)
GMap.FitBounds(MyBounds)
I have tried to use googlemapsextras to use LatLngBoundsBuilder, but i think it is only useable with android. So we have to find out the borders by an own subroutine or are there any other possibities?
I didn't try GoogleMapExtras. What do you mean by "find out the borders"?
 

rboeck

Well-Known Member
Licensed User
In GoogleMapsExtras exists a class called LatLngBoundsBuilder, which is used to calculate the optimal size from a list of markers; then you can use AnimatetoBounds to show the optimal zoomfactor.
 

Informatix

Expert
Licensed User
In GoogleMapsExtras exists a class called LatLngBoundsBuilder, which is used to calculate the optimal size from a list of markers; then you can use AnimatetoBounds to show the optimal zoomfactor.
There is no AnimateToBounds in the Google Maps API. Anyway, you can use the code in post #68 to do something similar. With a simple loop, you can set the expected params:
B4X:
Dim MinLatitude as Double = 99 'Latitude cannot go higher than 90
Dim MaxLatitude as Double = -99
For Each Marker As LatLon in MyListOfMarkers
    If Marker.Latitude < MinLatitude then MinLatitude = Marker.Latitude
    If Marker.Latitude > MaxLatitude then MaxLatitude = Marker.Latitude
...
 

Informatix

Expert
Licensed User
Here's the version 1.27 of jGoogleMaps:
- I added the ScrollWheel option to set whether the scroll wheel can zoom in/out;
- I added MoveCamera2(NewPosition As LatLng);
- I added the MapCircle class;
- I added the AddCircle and RemoveCircle functions;
- I renamed Polygon and Polyline to MapPolygon and MapPolyline to avoid naming issues with other libs;
- I added the RemoveMarker function.
 

Attachments

  • jGoogleMaps_1_27.zip
    251 KB · Views: 265

Informatix

Expert
Licensed User
Here's the version 1.28 of jGoogleMaps:
- Markers have a label now and their position can be read;
- I added the AddMarker3 function, which allows to specify an origin and an anchor position for the marker icon;
- I added the MapInfoWindow class;
- I added the AddInfoWindow, AddInfoWindow2, AddInfoWindowToMarker, and CloseInfoWindow functions;
- I added the CircleClick and PolygonClick events;
- I reduced the JAR size by removing unused files.

This version should cover most needs, so I don't think there will be another one from me before long.

Note to Erel: I made several changes to the original source code to add the missing functions/features, so be careful if you update this source code.
 

Attachments

  • jGoogleMaps_1_28.zip
    235.7 KB · Views: 367

JTmartins

Active Member
Licensed User
Hi,

Just tryed to use this library.

When I run from the IDE in release mode it works ok.

However, when I run the jar file that is generated in the objects folder, I cant see any map. It just shows a blank window.

No proxy or anything similar. Just a normal computer connected to the Internet.

What can cause this ?

Many thanks

******************
SOLVED.
Just had to move a few lines to other sub in my test app.

However is weird. Works when launched from the IDE, and was not working when launched directly.
******************
 
Last edited:

rboeck

Well-Known Member
Licensed User
Example2.png
Example1.png
Two days ago i bought my first iMac for testing. Before i tried an b4j app on windows and linux and now on an freshly installed iMac with El Capitan.
My problem, only on this machine: the font, which is used inside google maps is ? All text inside InfoWindows is unreadable, also the text, when you touch something inside google maps. Maybe its only a problem of this one machine, the i forget it; but if future customers have the same problem?
Also in webview i get the same strange results. I have looked through the fonts listing and didn't found anything strange. In webview maybe we could change the standard fonts with css.files, but in google maps i have no idea, where the problem comes from.
 

rboeck

Well-Known Member
Licensed User
I have a problem with version 1.50; all LatLng variables are getting red, it seems, that there was something lost in the new library. I went back to the last version and my program compiles ok.
 

Informatix

Expert
Licensed User
I have a problem with version 1.50; all LatLng variables are getting red, it seems, that there was something lost in the new library. I went back to the last version and my program compiles ok.
I confirm there's a lot of (my) code removed in the last version.
 
Status
Not open for further replies.
Top