多个标记未添加

时间:2015-10-27 14:17:37

标签: google-maps gmap.net

我正在尝试添加多个标记位置纬度和经度形成一个文件。但是只添加了一个标记,而且错误的位置也是如此。以下是我的代码,我在哪里做错了?我在windows窗体中使用gmap.net

private void button1_Click(object sender, EventArgs e)
    {
        string start = "Pune, Maharashtra, India";// textBox1.Text;
        string end = "Mumbai, Maharahtra, India"; //textBox2.Text;

        GDirections ss;
        var xx = GMapProviders.GoogleMap.GetDirections(out ss, start, end, false, false, false, false, false);
        GMapRoute r = new GMapRoute(ss.Route, "My route");

        GMapOverlay routesOverlay = new GMapOverlay("routes");

        r.Stroke.Width = 2;
        r.Stroke.Color = Color.Black;
        routesOverlay.Routes.Add(r);
        gmap.Overlays.Add(routesOverlay);

        //marker adding POI

        if (comboBox1.SelectedIndex == 0)
        {
           // MessageBox.Show("hotels");
            string line;
            GMapOverlay markersOverlay = new GMapOverlay("markers");

            // Read the file and display it line by line.
            System.IO.StreamReader file = new System.IO.StreamReader("D:\\hotels_lat_long"); // db file

            while ((line = file.ReadLine()) != null)
            {
                string[] Data_Array = line.Split(',');
                Double londecimal = Convert.ToDouble(Data_Array[0]);
                Double latdecimal = Convert.ToDouble(Data_Array[1]);
                //add a new one here                   
                var marker = new GMarkerGoogle(new PointLatLng(latdecimal, londecimal), GMarkerGoogleType.green);
                marker.IsVisible = true;

                markersOverlay.Markers.Add(marker);
                gmap.Overlays.Add(markersOverlay);                  
            }
            file.Close();               
        }

        if (comboBox1.SelectedIndex == 1)
        {
            //MessageBox.Show("Fuel Pumps");
        }

    }

1 个答案:

答案 0 :(得分:0)

我的愚蠢错误,本来应该是,我互换了纬度和经度值

Double londecimal = Convert.ToDouble(Data_Array[1]); 
Double latdecimal = Convert.ToDouble(Data_Array[0]);