开发者

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 U开发者_开发知识库RL 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();
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜