WebView cannot load Google map content in JavaFX 2.0

Viewed 542

When I double click the html file,there is a preview of the map, but when I load it in the WebView, no content will appear.

Here's the code:

StringBuilder sb = new StringBuilder();

InputStream in = getClass().getResourceAsStream("map.html");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while((line = reader.readLine()) != null){
    sb.append(line);
}
reader.close();

WebView browser = new WebView();
browser.setPrefSize(700, 550);
webEngine = browser.getEngine();
webEngine.loadContent(sb.toString());
webEngine.setOnAlert(new EventHandler<WebEvent<String>>(){
    @Override
    public void handle(WebEvent<String> event) {
        System.out.println("Alert Message > " + event.getData());
    }
});

Here's the html file named map.html:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"),
            mapOptions);
      }
    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:400px; height:300px"></div>
  </body>
</html>

What do you think is the problem? TAKE NOTE : The state of the webview's workloader is SUCCEEDED, meaning there is no ERROR.

0 Answers
Related