简体   繁体   中英

create polylines in gmap and generate image

I am trying to generate a gmap image in asp.net. I need to specify different latitude and longitude and generate google map image with polylines. So far, i am able to create image with the below code :

protected void btnMap_Click(object sender, EventArgs e)
{
    Save_Image("http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false");
}

private void Save_Image(string URL)
{
  WebClient client = new WebClient();
  string strFileName = DateTime.Now.GetHashCode().ToString() + ".png";
  client.DownloadFile(URL, Server.MapPath("~/images/" + strFileName));
  imgGmap.ImageUrl = "~/images/" + strFileName;
}

I am not able to find the way to pass the longitude and latitude in this url. I have checked this blog which is doing the same thing, but i am not finding the way to generate image with this demo.

According to the documentation you should be able to specify the path for a polyline like so:

path=color:0x0000ff|weight:5|40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397

eg

http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false&path=color:0x0000ff|weight:5|40.702147,-74.015794|40.711614,-74.012318|40.718217,-73.998284

Alternatively you can use the encoded polyline format (useful for shortening the URL significantly).

And you would specify that like:

&path=weight:3%7Ccolor:orange%7Cenc: polyline_data

To get that polyline_data, you could use the online form here: https://developers.google.com/maps/documentation/utilities/polylineutility

Alternatively write your algorithm based on the specification here: https://developers.google.com/maps/documentation/utilities/polylinealgorithm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM