B4J Question Google Map error

Declan

Well-Known Member
Licensed User
Longtime User
I use the following code to load the Google Map:
B4X:
Sub GMap_Ready
    Private joGMap As JavaObject  
    joGMap = GMap
    Dim event As Object = joGMap.CreateEventFromUI("com.lynden.gmapsfx.javascript.event.UIEventHandler", "MouseMove", Null)
    joGMap.GetFieldJO("map").RunMethod("addUIEventHandler", Array("mousemove", event))

    GMap.MapType = GMap.MAP_TYPE_TERRAIN
   
    Dim cp As CameraPosition
    cp.Initialize(-25.79886055, 28.32487679, 16)

    GMap.AddMarker2(-25.79886055, 28.32487679, "GOTCHA",File.GetUri(File.DirAssets, "helmet1.png"))

    GMap.MoveCamera(cp)
    Pane2.Visible = True
    pnlHistory.Visible = False
End Sub
However, the Map Image does not load and the following image is shown:
This was working without problems.
 

Attachments

  • NoImagery.png
    11.4 KB · Views: 113

Declan

Well-Known Member
Licensed User
Longtime User
Not enough information here for us to help you.
Here is additional code pertaining to Gmaps:
B4X:
#Region Project Attributes
    #MainFormWidth: 1200
    #MainFormHeight: 700
   
    '*********************
        #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;

    #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
    '*********************
   
    #JavaCompilerPath: 19, C:\java19\jdk-19.0.2\jdk-19.0.2\bin\javac.exe
    #AdditionalJar: mysql-connector-java-5.1.47.jar
   
#End Region
And:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    working=True
    ConnectAndReconnect ' MQTT Stuff
   
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show

    GMap.initialize2("GMap",GMapOptions,"AIzaSyAEZ2xfst5HXEiikHJeyFkRUBJ7KXXXXXX")
    pnlGoogleMaps.AddNode(GMap.AsPane, 0, 0, pnlGoogleMaps.Width, pnlGoogleMaps.Height)

    MarkerInfos.Initialize
End Sub
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I too have been experiencing this problem since yesterday.
But if I put a satellite map everything can be seen correctly. I still don't know what it depends on
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have had what might be a similar problem. I am not an experienced GoogleMaps user but a few weeks ago I wrote a B4A demo using GoogleMaps in reply to a question I received in a PM - my first use of GoogleMaps for nearly twenty years. I noticed earlier this week that the demo no longer worked - the app runs but no map appears. I assumed that my client secret or some similar requirement had expired - not something I needed to worry about.

Having seen these posts today I have taken a closer look, testing the app in Release mode through B4A Bridge. The app runs without any error messages appearing in the Log and without any map appearing on the screen. At this fragment of code . . .
B4X:
Sub MapFragment1_Ready
    points.Initialize
    Log("Waiting ...")
    Wait For MapFragment1_Ready
    Log("Ready!")
    gmap = MapFragment1.GetMap
    . . .

. . . both log messages appear, but no map fragment appears. Also I get the message shown below every time that I recompile the app - nothing like this happened when I first developed the app.

Edit : I now know that this dialogue comes from a Play Protect setting. That is what must have changed somehow - nothing to do with GoogleMaps.
 

Attachments

  • Screenshot.png
    127.3 KB · Views: 97
Last edited:
Upvote 0

Ralph Parkhurst

Member
Licensed User
Longtime User
I also have experienced the issue reported above with Google Maps under B4J on two apps - both stopped around mid week, although selecting Satellite Map does provide a partial workaround. Interestingly, I have a separate (not related) B4A mobile app which uses Google Maps which is running fine.

The GoogleMaps API 3.57.2 was updated earlier this week: https://developers.google.com/maps/documentation/javascript/releases#2024-05-28. No doubt this is connected with the issue.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Currently the jGoogleMaps library uses version 3.exp code which was used experimentally by developers. Maybe this is it
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
After trying many different Java / JavaFX / JS Google Maps versions, it looks like Google changed something and the Google Maps JS api is no longer compatible with JavaFX WebView.

As a test you can try it with:
B4X:
Dim we,wvjo As JavaObject
we.InitializeNewInstance("javafx.scene.web.WebEngine",Null)
wvjo = WebView1
we = wvjo.RunMethod("getEngine",Null)
Dim useragent As String=$"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"$
we.RunMethod("setUserAgent",Array(useragent))
WebView1.LoadUrl("https://alerts.skytruth.org/") 'random site that uses Google Maps

As this is not limited to B4J, I hope that we will find more information about this soon.
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
Same here. No Ime to display.

Same problem here.

[edit] - MAP_TYPE_SATELLITE works but NORMAL does not and HYBRID displays partially (the "NORMAL" component is missing). So it looks like the issue is with displaying only the street maps.
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I'm currently building a B4J library that interfaces with the browser to have the same functions I had with jGoogleMaps




 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I don't know, it's the first time I've even tried with Google. I'm gaining experience now
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
I don't know, it's the first time I've even tried with Google. I'm gaining experience now

What's nice about leaflet is that besides using Google Maps (without the need for an API key) you can use a variety of other maps. There are some people on this forum who have created a wrapper and library for leaflet, but it's too old and is severely limited.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Currently the jGoogleMaps library uses version 3.exp code which was used experimentally by developers. Maybe this is it
SOLVED

While working on my library I managed to get it working inside a WebView.

My intuition was right, version 3.56 should have been specified and not 3.exp which uses jGoogleMaps. And so it works correctly.

I don't know if @Erel will update his library. In case I will continue to develop mine


 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The issue is fixed with the help of @Star-Dust ?

An updated version was released (v2.01).
What happened is that the JS version was actually not set correctly. This was done in the open source GmapsFX project. The result was that the latest (weekly) version was used - v3.57. Setting it explicitly to 3.56, using @Star-Dust code fixes this issue. It is a temporary solution as v3.56 will only be available for several months. I hope that Google will fix the breaking change or that a workaround will be found. This is a general incompatibility between JavaFX WebView and Google JS SDK.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…