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: 329
  • GoogleMapExample.zip
    2.8 KB · Views: 203
Last edited:

rbghongade

Active Member
Licensed User
Longtime 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:

rboeck

Well-Known Member
Licensed User
Longtime 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
Longtime 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
Longtime 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
Longtime 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
Longtime 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: 455

Informatix

Expert
Licensed User
Longtime 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: 579

JTmartins

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

rboeck

Well-Known Member
Licensed User
Longtime 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.
 
Status
Not open for further replies.
Top