如何将参数传递给 URL 并获取生成的图像

发布于 2024-09-03 14:53:53 字数 747 浏览 3 评论 0原文

我想将几个参数传递给这个 url 并从中生成地图并在我的 java 应用程序中显示它。我知道下载图像并在java应用程序中显示它的代码。我想知道如何将参数传递到这个地址:

http://maps.google.com/maps/api/staticmap?center =Nugegoda&zoom=14&size=1000x312&maptype=roadmap&markers=color:blue|label:S|size=tiny|Mirihana&markers=size:mid|color:0xFFFF00|label:C|Udahamulla&sensor=false

在此链接中,Nugegoda、Mirihana 和 Udahamulla 是我应该从申请中通过的链接。然后它会生成一个图像,我确实需要显示它。即使你检查这个链接。这是一个图像。

有人可以帮助我吗?

I want to pass several parameters to this url and generate the map from it and show it in my java application. I know the code to download the image and show it in the java application. I want to know how to pass parameters to this address:

http://maps.google.com/maps/api/staticmap?center=Nugegoda&zoom=14&size=1000x312&maptype=roadmap&markers=color:blue|label:S|size=tiny|Mirihana&markers=size:mid|color:0xFFFF00|label:C|Udahamulla&sensor=false

In this link Nugegoda and Mirihana and Udahamulla is the one that i should pass from the application. And then it will generate a image and i do need to show it. Even if u check this link. It's a image.

Can someone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海里的那抹蓝 2024-09-10 14:53:53

静态地图 API 可以执行地理编码 如果您将有效地址传递给 center 参数:

https:/ /maps.google.com/maps/api/staticmap?center=Nugegoda&zoom=14&size=400x400&sensor=false

Nugegoda

您可以传递的参数都是列于此处。按照 URL 的标准,所有参数均使用与号 & 字符分隔。因此,如果您想添加 maptype 参数并将其设置为 hybrid,例如,您只需在上面添加 &maptype=hybrid 即可网址:

https://maps.google.com/maps/api/staticmap?center=Nugegoda&zoom=14&size=400x400&sensor=false&maptype=hybrid

Nugegoda

然后,如果您想显示 Udahamulla 地图,只需将 Nugegoda 替换为 Udahamulla 即可center 参数:

https:// /maps.google.com/maps/api/staticmap?center=Udahamulla&zoom=14&size=400x400&sensor=false

Udahamulla


更新:

除了下面的评论之外,您可以使用 < code>path 参数,如下:

https://maps.google.com/maps/api/staticmap?center=Udahamulla&zoom=13&size=400x400&path=color:0xff0000ff|weight:5|Maharagama |Nugegoda&sensor=false

Maharagama to Nugegoda

请注意 API 如何对地址“Maharagama”和“Nugegoda”进行地理编码,因此您无需传递地点的纬度和经度坐标。

目前,静态地图 API 不提供行车路线指示。不过,如果您有复杂路线的点,则可以将路径绘制为编码的折线

The Static Maps API can do geocoding for you if you pass a valid address to the center parameter:

https://maps.google.com/maps/api/staticmap?center=Nugegoda&zoom=14&size=400x400&sensor=false

Nugegoda

The parameters that you can pass are all listed here. As is standard in URLs, all parameters are separated using the ampersand & character. Therefore if you want to add the maptype parameter and set it to hybrid for example, you can simply add &maptype=hybrid to the above URL:

https://maps.google.com/maps/api/staticmap?center=Nugegoda&zoom=14&size=400x400&sensor=false&maptype=hybrid

Nugegoda

Then if you want to show the Udahamulla map, simply replace Nugegoda with Udahamulla for the center parameter:

https://maps.google.com/maps/api/staticmap?center=Udahamulla&zoom=14&size=400x400&sensor=false

Udahamulla


UPDATE:

Further to the comments below, you can add a polyline on a static map by using the path parameter, as follows:

https://maps.google.com/maps/api/staticmap?center=Udahamulla&zoom=13&size=400x400&path=color:0xff0000ff|weight:5|Maharagama|Nugegoda&sensor=false

Maharagama to Nugegoda

Note how the API geocodes the addresses "Maharagama" and "Nugegoda", so you do not need to pass the latitude and longitude coordinates of the localities.

Currently the Static Maps API does not do driving directions. However if you have the points of a complex route, you could plot the path as an encoded polyline.

谢绝鈎搭 2024-09-10 14:53:53

您可以使用 Google 静态地图 API。如果你纯粹想插入变量,你可以这样做:

String center = ...;
String labelS = ...;
String labelC = ...;

String url = "http://maps.google.com/maps/api/staticmap?center=" 
+ center 
+ "&zoom=14&size=1000x312&maptype=roadmap&markers=color:blue|label:S|size=tiny|" 
+ labelS 
+ "&markers=size:mid|color:0xFFFF00|label:C|" + labelC + "&sensor=false";

You can use the Google Static Maps API. If you purely want to interpolate variables, you can do:

String center = ...;
String labelS = ...;
String labelC = ...;

String url = "http://maps.google.com/maps/api/staticmap?center=" 
+ center 
+ "&zoom=14&size=1000x312&maptype=roadmap&markers=color:blue|label:S|size=tiny|" 
+ labelS 
+ "&markers=size:mid|color:0xFFFF00|label:C|" + labelC + "&sensor=false";
梦里梦着梦中梦 2024-09-10 14:53:53

您的问题是“如何构造一个包含一些可变部分的字符串?”当您在应用程序中构建 URL 字符串时,它“只是”一个字符串。您可以连接不同的部分,或使用格式化打印。 (请参阅格式。)

(给定的 URL 已经有许多参数:问号后面的每一对都是变量名称和值。)

Is your question "How do I construct a String that has some variable parts in it?" At the time you build the URL string in your application, it is 'just' a String. You can concatenate the different parts, or use formatted printing. (See format.)

(The URL given already has a number of parameters: every pair behind the question mark is a variable name and value.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文