如何在ASP.Net gridview控件中显示yahoo静态地图?加载地图的地址将出现在gridview的一列中,并且基于每行的地址,静态地图必须在每一行上显示。
答案 0 :(得分:0)
我已经完成了在ASP.Net网页上显示静态地图的代码。我们可以在gridview的row databound事件中调用DisplayYStaticMap方法,并在gridview中显示yahoo静态地图。
public static string DisplayYStaticMap(string streetName,string CityName,string stateName,int imgWidth,int imgHeight,int zoom) { WebClient wc = new WebClient();
StringBuilder strb = new StringBuilder();
strb.Append("http://local.yahooapis.com/MapsService/V1/mapImage?Appid=YOURAPIID--&");
if (streetName != "")
{
strb.Append("street=");
strb.Append(streetName);
}
if (CityName != "")
{
strb.Append("&city=");
strb.Append(CityName);
}
if (stateName != "")
{
strb.Append("&state=");
strb.Append(stateName);
}
if (imgHeight != 0)
{
strb.Append("&image_height=");
strb.Append(imgHeight);
}
if (imgWidth != 0)
{
strb.Append("&image_width=");
strb.Append(imgWidth);
}
if (zoom != 0)
{
strb.Append("&zoom=");
strb.Append(zoom);
}
string str = wc.DownloadString(strb.ToString());
if (str.IndexOf("--&") != -1)
{
return str.Substring(str.IndexOf("http://gws.maps.yahoo.com"), str.IndexOf("--&"));
}
else
{
return str.Substring(str.IndexOf("http://gws.maps.yahoo.com"));
}
}
}
imgPhotos.Src = DisplayYStaticMap(ds.Tables [0] .Rows [0] [“PropertyAddress”]。ToString()。Substring(0,ds.Tables [0] .Rows [0] [“PropertyAddress”]的ToString()。的IndexOf( “”)), ds.Tables [0] .Rows [0] [“PropertyCity”]。ToString(),ds.Tables [0] .Rows [0] [“PropertyState”]。ToString(),150,90,8); < / p>