Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does new versions of google map's javascript versions work on JavaFx-WebView

I am trying to load google map on JavaFx-WebView, and it doesn't show anything except background color of html body that i have coded on html file. Also i tried some examples on Google search, all the result were older. None of it works. My Java version is "1.8.0_121"

I wrote a html file & run it. It loaded google maps successfully. Then i load the html file to webview using webEngine.load("path") method. it doesn't show anything except backgound color.

After that I tried http://rterp.github.io/GMapsFX

  • runs ClusteredMainApp.java (put my google api key)
  • consoles outputs are:
  • "hier"
  • "clustererimages/m"
  • "Hide directions called"
  • "loadMapLibrary"
  • "loadMapLibrary done"
  • "initMap"
  • "LatLong: (47.606189, -122.33584200000001)"
  • "netscape.javascript.JSException: Error: The Google Maps JavaScript API does not support this browser. (undefined,0)"

Also i couldn't find any solutions for this error

Html File

CSS:

#map_canvas { height: 100%; background-color: blue; }

javascript:

function initialize() {
                var latlng = new google.maps.LatLng(37.39822, -121.9643936);
                var myOptions = {
                    zoom: 14,
                    center: latlng,
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    mapTypeControl: false,
                    navigationControl: false,
                    streetViewControl: false,
                    backgroundColor: "#666970"
                };

                document.geocoder = new google.maps.Geocoder();
                document.map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

}

html:

<body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
   </body>

JavaFX:

public class WebMap extends Application {
 
    @Override public void start(Stage stage) {
        // create web engine and view
        final WebView webView = new WebView();
        final WebEngine webEngine = webView.getEngine();
        webEngine.load(getClass().getResource("WebMap.html").toString());
        // create scene
        stage.setTitle("Web Map");
        Scene scene = new Scene(webView,1000,700, Color.web("#666970"));
        stage.setScene(scene);
        // show stage
        stage.show();
    }
 
    public static void main(String[] args){
        Application.launch(args);
    }
}
like image 610
Shanaka Madusanka Avatar asked Jun 18 '19 05:06

Shanaka Madusanka


1 Answers

Google maps API dropped support for older browsers which started causing the "The Google Maps JavaScript API does not support this browser." error. Look at https://developers.google.com/maps/documentation/javascript/releases and https://developers.google.com/maps/documentation/javascript/versions.

The library you are using is using version 3.exp (experimental).

Running on a newer Java version will fix this (for now).

like image 142
Lightah Avatar answered Oct 02 '22 13:10

Lightah