2012-08-10 71 views
0

我有sql服務器表,其中一列是緯度和其他列是經度。我有這個表950行。現在我想爲所有這950行添加谷歌地圖標記點。所以總共爲950分。我正在使用Google地圖控件來處理這個任務。爲了在地圖中添加單個點,以下是代碼。asp.net的谷歌地圖

GooglePoint GP = new GooglePoint(); 
GP.Latitude = 43.65669; 
GP.Longitude = -79.43270; 
GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP); 

現在我想借此lat和長從我的SQL Server table.so,它應該增加自身所有的點在map.Please幫助我該怎麼辦this.Any示例代碼? 現在我已經嘗試了這個代碼。但是我沒有明白這一點。

protected void Page_Load(object sender, EventArgs e) 
    { 
     GoogleMapForASPNet1.GoogleMapObject.Width = "1000px"; 
     GoogleMapForASPNet1.GoogleMapObject.Height = "800px"; 
     GoogleMapForASPNet1.GoogleMapObject.MapType = "Hybrid"; 

     SqlConnection con = new SqlConnection(); 
     con.ConnectionString = "Data Source=GEOFINY5;Initial Catalog=sample;Integrated Security=True"; 
     try 
     { 
      SqlCommand cmd = new SqlCommand("Select lat,long from map",con); 
      con.Open(); 
      SqlDataReader dr = cmd.ExecuteReader(); 
      //int i = 0; 
      while (dr.Read()) 
      { 
       GooglePoint gp = new GooglePoint(); 
       //gp.ID = i.ToString; 
       gp.Latitude = Convert.ToDouble(dr.GetValue(1)); 
       gp.Longitude = Convert.ToDouble(dr.GetValue(2)); 
       gp.InfoHTML = "Hello!!"; 
       GoogleMapForASPNet1.GoogleMapObject.Points.Add(gp); 
      } 
      con.Close(); 

     } 
     catch(Exception ex) 
     { 

     } 

    } 

注: 我使用谷歌地圖的JavaScript API V3與融合表already.But現在我寧願與SQL Server,而不是融合表做。

回答

0

嘗試以這種方式

<iframe align="middle" width="800" height="400" src="http://regiohelden.de/google-maps/map.php?width=800&amp;height=400&amp;hl=de&amp;q=<%#Eval("Hotel_Address") %> <%#Eval("Hotel_City") %>+(<%#Eval("Hotel_Name") %>)&amp;ie=UTF8&amp;t=&amp;z=16&amp;iwloc=B&amp;output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe> 

在web.config文件中使用此

<appSettings> 
    <add key="googlemaps.subgurim.net" value="ABQIAAAA5b0MiuEiQRYUHB2eaeT5XRRRh87LaJKgnubN7EENjpWM3qNBVhSyngHVcUObtYAlLD3CLsIR0Jd7TA"/> 
<add key="localhost.SlideShow" value="http://localhost/maabookings/SlideShow.asmx"/> 
</appSettings>