2011-05-31 51 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)解決了我的問題。

相關問題