2010-10-05 65 views
0

如何在ASP.Net gridview控件中顯示雅虎靜態地圖?加載地圖的地址將出現在gridview的其中一列中,並且基於每行的地址來顯示每行上的靜態地圖。如何將雅虎靜態地圖整合到ASP.Net網站中

+0

此鏈接http://developer.yahoo.com/maps/rest/V1/的代碼是用PHP語言顯示Yahoo靜態地圖,但我想用ASP.Net或C#.Net語言或javascript。 – banupriya 2010-10-05 11:49:38

回答

0

我已經完成了在ASP.Net網頁上顯示靜態地圖的代碼。我們可以在gridview的行數據綁定事件中調用DisplayYStaticMap方法,並在gridview中顯示yahoo靜態地圖。

公共靜態字符串DisplayYStaticMap(串streetName,串CITYNAME,串Statename的,INT imgWidth,INT imgHeight,INT變焦) { Web客戶端WC =新Web客戶端();

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