0

我正在尝试绘制折线,但在重载方法中存在一些错误,我无法理解为什么当我正确执行它时会导致错误......我的代码,

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

现在它给了我脚本折线不存在的错误

希望得到您的回复...

4

1 回答 1

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); 
于 2011-08-12T05:52:11.107 回答