2011-05-31 62 views
1

我需要使用指向Google静态图的URL从我的Java Swing应用程序打开浏览器。从Java Swing应用程序打开Goog​​le静态图

我用的是1.6的桌面类打开浏览器,但我收到以下错误:

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.

然而,当我打开Internet Explorer并粘贴URL,它工作正常。

为什么Internet Explorer不能正常工作?这是网址:

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

下面是代码snipplet,我打开网址:

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

也许张贴代码片段,您尝试打开URL ... – MatrixFrog 2011-05-31 04:05:43

回答

1

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

相关问题