我需要从 Java Swing 应用程序中打开一个浏览器,其中的 URL 指向 Google 的静态 map 。
我使用 1.6 Desktop 类打开浏览器,但收到以下错误:
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 无法工作?这是网址:
这是我打开 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();
}
}
最佳答案
已解决。我改变了图像的格式。谷歌地图默认下载 png 图像。 更改为 gif(参数 &format=gif)解决了我的问题。
关于java - 从 Java Swing 应用程序打开 Google 静态 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6182456/