B4J Question jGoogle Maps 2.01

Philip Prins

Active Member
Licensed User
Longtime User
I think Google changed something again:
1740144478768.png


No imagery here notice.

I followed all the steps in the previous update , JDK 19.0.02

Can anyone check if it still works on their side?

Regards
Philip
 

Daestrum

Expert
Licensed User
Longtime User
Using the new PyBridge you can use folium in a webview.
B4X:
Sub folium_test
    wait for ((Py.RunCode("start",Array("Greenwich, UK"),File.ReadString(File.DirAssets,"folium_test.py")).Fetch)) Complete (res As PyWrapper)
    WebView1.LoadHtml(File.ReadString("../objects",res.value)) ' << change to suit - being lazy I let it save in /Objects
End Sub

Python code
Python Code to use Folium:
import folium
import requests

def get_lat_lon(place_name):
    url = f"https://nominatim.openstreetmap.org/search?q={place_name}&format=json"
    headers = {
        'User-Agent': 'AddressLookup/1.0 (an email address)'
    }
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        try:
            data = response.json()
            if data:
                lat = data[0]['lat']
                lon = data[0]['lon']
                return lat, lon
            else:
                print("No data found for the specified place name.")
                return None
        except ValueError:
            print("Invalid JSON response.")
            return None
    else:
        print(f"Error: {response.status_code}")
        return

def start(place):
    lat,lon = get_lat_lon(place)
    # Create a map centered around London
    map_london = folium.Map(location=[lat,lon], zoom_start=12)

    # Add a marker for Home
    folium.Marker(
        location=[lat,lon],
        popup="Marker",
        icon=folium.Icon(icon="London")).add_to(map_london)
  
    # Save the map to an HTML file
    map_london.save("london_map.html")

    # Open the saved map in the default web browser
    #webbrowser.open("london_map.html")

    return "london_map.html"
1740906667571.png
 
Upvote 0

javiers

Active Member
Licensed User
Longtime User
Everything is explained in this thread. There is no solution for this, until JavaFX is updated and supports Google maps SDK.
A possible workaround is to use Java 8.
Yes, thanks for the response. I was precisely referring to seeing if there was any news about how the JavaFX adaptation was going...
I understand that it is difficult to have a possible forecast of when it can be adapted?
Sorry for my English (Google translator)
 
Upvote 0

javiers

Active Member
Licensed User
Longtime User
Using the new PyBridge you can use folium in a webview.
B4X:
Sub folium_test
    wait for ((Py.RunCode("start",Array("Greenwich, UK"),File.ReadString(File.DirAssets,"folium_test.py")).Fetch)) Complete (res As PyWrapper)
    WebView1.LoadHtml(File.ReadString("../objects",res.value)) ' << change to suit - being lazy I let it save in /Objects
End Sub

Python code
Python Code to use Folium:
import folium
import requests

def get_lat_lon(place_name):
    url = f"https://nominatim.openstreetmap.org/search?q={place_name}&format=json"
    headers = {
        'User-Agent': 'AddressLookup/1.0 (an email address)'
    }
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        try:
            data = response.json()
            if data:
                lat = data[0]['lat']
                lon = data[0]['lon']
                return lat, lon
            else:
                print("No data found for the specified place name.")
                return None
        except ValueError:
            print("Invalid JSON response.")
            return None
    else:
        print(f"Error: {response.status_code}")
        return

def start(place):
    lat,lon = get_lat_lon(place)
    # Create a map centered around London
    map_london = folium.Map(location=[lat,lon], zoom_start=12)

    # Add a marker for Home
    folium.Marker(
        location=[lat,lon],
        popup="Marker",
        icon=folium.Icon(icon="London")).add_to(map_london)
 
    # Save the map to an HTML file
    map_london.save("london_map.html")

    # Open the saved map in the default web browser
    #webbrowser.open("london_map.html")

    return "london_map.html"
View attachment 162181
For me, Python is something very new, and I think perhaps for many others. Would it be possible here or in another thread (perhaps tutorial) to give an example of using folium?
Many of us would appreciate it!
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Small update, but not decisive. Using JCEF that supports webgl it is possible to correctly see Google pages and use and Googlemaps APIs.
In Java it works properly, even if I have not yet understood the browser's life cycle well and it stops me, I have to study again.

After a week I managed to integrate JCEF in B4J, but I can't add browser in Javafx, he uses Swing. The most important thing is the life cycle, surely something is wrong.

Now I have to stop for a week in the least, I have to work every now and then

1741092350256.png
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
We’ve finally reached a turning point!
Over the past three weeks, I’ve conducted numerous tests, exploring some undocumented functions to disable WebGL in Google Maps. The goal was to make maps.google.com work correctly in WebView, but the results were unsatisfactory. I also tried forcing rendering in Canvas and, finally, configuring Google Maps to generate only static JPG images, but none of these solutions proved practical or worked as hoped.

I explored all the alternatives to WebView, such as JCEF based on Chromium, but even this approach turned out to be difficult and full of obstacles.

In the end, after dozens of trials, I decided to switch to OpenMap with Leaflet. However, even this choice wasn’t without its challenges: OpenMap can’t directly replace Google Maps, as the events and methods it offers are different from those of the GMap library.

I then concluded that the fastest solution, to avoid rewriting all the code for apps using Google Maps, was to create a new library based on OpenMap, but with the same methods and events. So, in just two days, I managed to rewrite it. It wasn’t easy, especially due to the communication issues between WebView and B4J with Java 19, but with some tricks that cost me a whole day, I managed to resolve everything.

I’ll soon be releasing a library that will allow you to replace Google Maps without having to modify existing code. I’m currently testing it and also developing a second library to replace GoogleMapExt, which is widely used, and that also needs to be rewritten to maintain compatibility with the existing code.


1741648411564.png
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
I’ll soon be releasing a library that will allow you to replace Google Maps without having to modify existing code. I’m currently testing it and also developing a second library to replace GoogleMapExt, which is widely used, and that also needs to be rewritten to maintain compatibility with the existing code.

Wow! This would be amazing. I have been hoping for something like this for a while and was looking at the possibility of doing it myself but just don't have the requisite knowledge at the moment. It would be nice to get away from Google Maps. Would you be able to select other map providers supported by Leaflet besides OpenMaps? See below:



BTW: By OpenMaps do you mean OSM - Open Street Maps?

Thanks!
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
At the moment inserted what is available in Google for library compatibility: Normal, satellite, hybrid, terrain
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
PS: important.

I got many functions with Javaobject, such as making markers, polygons etc ... now this part of code not function. I added in the second library functions that replace them.
So I have what was achieved with Javaobject should be eliminated. Unfortunately a minimum of modification must be made

OpenMaps Library
 
Last edited:
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Great work @Star-Dust
The following solution is also available:

 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Great work @Star-Dust
The following solution is also available:
Thanks for your contribution, it will be useful for those who need to represent a map and markers. the library has made it and produces all the commands and events that are present in the jgooglemaps library so you can replace the library without having to rewrite the code.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Thanks for your contribution, it will be useful for those who need to represent a map and markers. the library has made it and produces all the commands and events that are present in the jgooglemaps library so you can replace the library without having to rewrite the code.

👍 Really great work
 
Upvote 0

Arnaud

Active Member
Licensed User
Longtime User
Hello,

I have found something strange. In my side, Google map work fine always, but only if the screen size of my PC is 100%. If I change the size / zoom of the screen of my PC, I have the bug

Please the result in attachment, I don't know if there is a link with the problem in header
 

Attachments

  • 1742574272677.png
    1742574272677.png
    119.4 KB · Views: 21
  • Goole map error at 125%.png
    Goole map error at 125%.png
    296.2 KB · Views: 22
  • Google map OK.png
    Google map OK.png
    446.6 KB · Views: 24
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
Hello,

I have found something strange. In my side, Google map work fine always, but only if the screen size of my PC is 100%. If I change the size / zoom of the screen of my PC, I have the bug

Please the result in attachment, I don't know if there is a link with the problem in header

I have encountered problems with jGoogleMaps and screen size/scaling before. I use a 4k native monitor and had problems in B4J using the Windows recommended 150%, only 100% and 200% worked for me.

I tried the 1920x1080 at 100% suggested by @Arnaud but no joy in either NORMAL or SATELLITE.
 
Upvote 0

Ralph Parkhurst

Member
Licensed User
Longtime User
I have encountered problems with jGoogleMaps and screen size/scaling before. I use a 4k native monitor and had problems in B4J using the Windows recommended 150%, only 100% and 200% worked for me.

I tried the 1920x1080 at 100% suggested by @Arnaud but no joy in either NORMAL or SATELLITE.

I recommend switching to Star-Dust's new jSD_OpenMaps library - see post #32 above. It works very well and gives you a greater choice of maps since it is based on Leaflet.
 
Last edited:
Upvote 0
Top