1

I'm making a java app desktop and I need to put in a form a map. Searching online I found that I can show google map with javascript. This is the code named map.html:

<!DOCTYPE html><html><head>
<title>City Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
    html, body {
        height: 100%;
        margin: 0;
        padding: 0;
    }
    #map {
        height: 100%;
    }
</style></head><body><div id="map"></div><script>
var map;
function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
        center: {
            lat: -34.397,
            lng: 150.644},
        zoom: 8
    });
}</script><script src="myAPI KEY" async defer></script></body></html>

I want to put this map inside a Jpanel, but I don't find a solution to do this. Java GUI code:

public class Login {
private JPanel panel1;
private JButton button1;
public static void main(String argv[]){

    JFrame pannello = new JFrame("map.html");
    pannello.setContentPane(new Login().panel1);
    pannello.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pannello.pack();
    pannello.setVisible(true);
}}

Someone can help me? Thanks

P.S. I don't know if it's the best solution to show a google map

lospejos
  • 1,976
  • 3
  • 19
  • 35
dvdLucka
  • 51
  • 7
  • 2
    IMHO, you have to consider embedding browser into some Swing component and deal with it. I'm afraid default Java Swing Panel cannot display all modern javascript-aware pages like Google Map so you'll most probably will lost some map functionality. – lospejos Oct 10 '16 at 14:17
  • Actually not a [duplicate](http://stackoverflow.com/q/19701105/3892340) (...maybe?), but contains the right answer. – GustavoCinque Oct 10 '16 at 14:26
  • I've found JxMaps and JxBrowser, but they are in demo for 30days. In case I embed browser "zone" in my form, the map can be used? – dvdLucka Oct 10 '16 at 14:29
  • [This one](http://stackoverflow.com/a/18164676/3892340) doens't seen to use neither JxMaps, nor JxBrowser. Have you tried it? I don't know anything in more detail regarding Swing, just trying to help you out. – GustavoCinque Oct 10 '16 at 14:33
  • takes an image of google maps with given coordinates. My java app should use a dynamic map – dvdLucka Oct 10 '16 at 14:41
  • Why not instead of Java, create an HTML/CSS/JavaScript application? That would make things *much* easier. – Hovercraft Full Of Eels Oct 10 '16 at 14:48
  • I know, but the project we are working, must be a java desktop app – dvdLucka Oct 10 '16 at 14:50
  • Probably you can try a Chromium Embed Framework for Java in order to load web page in your application: https://en.wikipedia.org/wiki/Chromium_Embedded_Framework. – xomena Oct 12 '16 at 12:27

0 Answers0