0

我正在尝试在 asp.net 中生成 gmap 图像。我需要指定不同的纬度和经度,并使用折线生成谷歌地图图像。到目前为止,我可以使用以下代码创建图像:

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

我无法找到在此网址中传递经度和纬度的方法。我检查了这个做同样事情的博客,但我没有找到用这个演示生成图像的方法。

4

1 回答 1

1

根据文档,您应该能够像这样指定折线的路径:

路径=颜色:0x0000ff|重量:5|40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397

例如

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

或者,您可以使用编码的折线格式(用于显着缩短 URL)。

你会指定这样的:

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

要获取该 polyline_data,您可以使用此处的在线表格: https ://developers.google.com/maps/documentation/utilities/polylineutility

或者根据此处的规范编写您的算法: https ://developers.google.com/maps/documentation/utilities/polylinealgorithm

于 2013-05-30T08:49:14.013 回答