开发者

how to pass parameters to a URL and get the generated image

开发者 https://www.devze.com 2023-01-01 20:44 出处:网络
Iwant 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

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?


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.


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";


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消