2011-08-12 45 views
0

我想繪製折線,但是在重載方法中有一些錯誤,我無法得到它爲什麼導致錯誤,當我正確地做它時...我的代碼,試圖繪製折線導致錯誤C#Web應用程序

private void BuildScript(DataTable tbl) 
     { 
      String Locations = ""; 
      String locations = ""; 
      foreach (DataRow r in tbl.Rows) 
      { 
       // bypass empty rows   
       if (r["Latitude"].ToString().Trim().Length == 0) 
        continue; 

       string Latitude = r["Latitude"].ToString(); 
       string Longitude = r["Longitude"].ToString(); 
       double latitude = Convert.ToDouble(r["Latitude"]); 
       double longitude =Convert.ToDouble(r["Longitude"]); 
       var points = new List<GLatLng> {new GLatLng(latitude,longitude)}; 
       var polyline = new GPolyline(points); 
       // create a line of JavaScript for marker on map for this record  
       Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + Latitude + "," + Longitude + ")));"; 
       locations += Environment.NewLine + " map.addOverlay(new GPolyline(new GLatLng(" + Latitude + "," + Longitude + ")));"; 
      } 

      // construct the final script 
      js.Text = @"<script type='text/javascript'> 
          function initialize() { 
           if (GBrowserIsCompatible()) { 
           var map = new GMap2(document.getElementById('map_canvas')); 
           map.setCenter(new GLatLng(45.05,7.6667), 2); 
           " + Locations + @" 
           map.setUIToDefault(); 
           } 
          } 
          </script> "; 
    js.Text = @"<script type='text/javascript'> 
          function initialize() { 
           if (GBrowserIsCompatible()) { 
           var map = new GMap2(document.getElementById('map_canvas')); 
           map.setCenter(new GLatLng(45.05,7.6667), 2); 
           " + locations + @" 
           map.setUIToDefault(); 
           } 
          } 
          </script> "; 
} 

現在它給我的錯誤在腳本折線不exsis

的希望您的回覆...

+0

當我「的字符文字字符太多」刪除與「#FF0000」單引號雙qoutes通過「#FF0000」它會導致錯誤?? –

+0

因爲在C#中,單引號僅用於指定單個字符(例如'A')。一個字符串必須用雙引號括起來。 – shf301

+0

看起來您正嘗試在C#中使用JavaScript語法。我很驚訝你的第一行甚至編譯。 – shf301

回答

1

的GPolyline構造函數需要的類型List<GLatLng>的變量,這不是你的正通過。

您需要創建您的GLatLng值的列表:

var points = new List<GLatLng> { new GLatLng(59.6919, 17.8582),new GLatLng(59.3030, 18.0395),new GLatLng(58.9789, 17.5341) }; 
var polyline = new GPolyline(points,"#ff0000",1); 
+0

Post edited請看看它 –