how to pass parameters to a URL and get the generated image
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
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
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
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
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.)
精彩评论