bahrinka
bahrinka

Reputation: 11

Opening a Google staticmap from Java Swing application

I need to open a browser from my Java Swing application with a URL pointing to a staticmap from Google.

I use the 1.6 Desktop class to open the browser, but I am getting the following error:

Internet Explorer cannot download staticmap from mpas.google.com. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

However, when I open Internet Explorer and paste the URL it works fine.

Why is Internet Explorer not working? This is the URL:

http://maps.google.com/maps/api/staticmap?zoom=6&size=400x400&markers=color:green%7Clabel:1%7C30.652934,-95.575821&sensor=false

Here is the code snipplet where I open the URL:

Desktop desktop = Desktop.getDesktop();
if (!desktop.isSupported(Desktop.Action.BROWSE)) {
    System.out.println("Desktop does not support browse mode.");
} else {
    try {
        URI uri = new URI("http://maps.google.com/maps/api/staticmap?zoom=6&size=400x400&markers=color:green%7Clabel:1%7C40.837375,-85.646872&sensor=false");
        desktop.browse(uri);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

Upvotes: 1

Views: 902

Answers (1)

mark
mark

Reputation: 11

Solved. I changed the format of the image. Google maps download as default a png image. Changing to gif (parameter &format=gif) solved my problem.

Upvotes: 1

Related Questions