从Java Swing应用程序打开Goog​​le静态地图

时间:2011-05-31 02:33:58

标签: java maps desktop

我需要从我的Java Swing应用程序打开一个浏览器,其URL指向来自Google的静态地图。

我使用1.6 Desktop类打开浏览器,但是我收到以下错误:

  

Internet Explorer无法从mpas.google.com下载静态地图。   Internet Explorer无法打开此Internet站点。该   请求的网站不可用或无法找到。请试试   再来一次。

但是,当我打开Internet Explorer并粘贴URL时,它可以正常工作。

为什么Internet Explorer无法运行?这是URL:

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

以下是我打开网址的代码信息:

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();
    }
}

1 个答案:

答案 0 :(得分:1)

解决。我改变了图像的格式。谷歌地图下载默认为png图像。 更改为gif(参数& format = gif)解决了我的问题。