我需要从 Java Swing 应用程序中打开一个浏览器,其中的 URL 指向 Google 的静态地图。
我使用 1.6 Desktop 类打开浏览器,但出现以下错误:
Internet Explorer 无法从 mpas.google.com 下载静态地图。
Internet Explorer 无法打开此 Internet 站点。这
请求的站点不可用或无法找到。请尝试
稍后再说。
但是,当我打开 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
这是我打开 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();
}
}
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 URL 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();
}
}
发布评论
评论(1)
解决了。我改变了图像的格式。谷歌地图默认下载 png 图像。
更改为 gif(参数 &format=gif)解决了我的问题。
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.