Trying To Draw polyline Resulting in Error C# Web App

独自空忆成欢 提交于 2019-12-25 02:22:49

问题


I am trying to draw polyline but there is some error in in overloading method which i can not get why it is resulting in error when i am doing it correctly... my code,

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

now it is giving me error in script polyline does not exsis

Hopes for your reply ...


回答1:


The GPolyline constructor requires a variable of the type List<GLatLng> and that's not what your are passing in.

You need to create your GLatLng values as a List:

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


来源:https://stackoverflow.com/questions/7035983/trying-to-draw-polyline-resulting-in-error-c-sharp-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!