How can I add multiple markers using gmap.net in c# windows form

Topics: Windows Forms
Jul 2, 2013 at 1:01 PM
Edited Jul 2, 2013 at 1:03 PM
I tried many ways but not to success my windows does not point to any markers.
 if (comboBox5.SelectedIndex == 0)//(REGION 1)
            {
               
                String Query = " SELECT top 500  Latitude,Longitude  FROM  [Sheet3_kir]   ";
                SqlConnection conDatabase = new SqlConnection(constring);
                SqlCommand cmdDatabase = new SqlCommand(Query, conDatabase);
                SqlDataReader myReader;
                gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
                GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;

                GMapOverlay markersOverlay = new GMapOverlay("VCS MAP");
              

                    for (int i = 0; i <= dataGridView1.Rows.Count; i++)
                    {
                        foreach (DataGridViewRow row in dataGridView1.Rows)
                        {
                            var Latitude = double.Parse((dataGridView1.Columns[1].ToString()), CultureInfo.InvariantCulture);
                            var Longitude = double.Parse((dataGridView1.Columns[2].ToString()), CultureInfo.InvariantCulture);
                            //gMapControl1.Position = new PointLatLng(Latitude, Longitude);
                           // GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(float.Parse(this.dataGridView1.Columns[1].ToString), if (comboBox5.SelectedIndex == 0)//(REGION 1)
            {
                string constring = "Data Source = 192.168.0.8 ; USER ID  = sa ; PASSWORD = excel";
                String Query = " SELECT top 500  Latitude,Longitude  FROM[ICPS].[dbo].[Sheet3_kir]   ";
                SqlConnection conDatabase = new SqlConnection(constring);
                SqlCommand cmdDatabase = new SqlCommand(Query, conDatabase);
                SqlDataReader myReader;
                gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
                GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;

                GMapOverlay markersOverlay = new GMapOverlay("VCS MAP");
              

                    for (int i = 0; i <= dataGridView1.Rows.Count; i++)
                    {
                        foreach (DataGridViewRow row in dataGridView1.Rows)
                        {
                            var Latitude = double.Parse((dataGridView1.Columns[1].ToString()), CultureInfo.InvariantCulture);
                            var Longitude = double.Parse((dataGridView1.Columns[2].ToString()), CultureInfo.InvariantCulture);
                            //gMapControl1.Position = new PointLatLng(Latitude, Longitude);
                           // GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(float.Parse(this.dataGridView1.Columns[1].ToString), float.Parse(this.textBox26.Text)),
            // GMarkerGoogleType.green);
                           // GMarkerGoogle m = new GMarkerGoogle(gMapControl1.Position, GMarkerGoogleType.green_pushpin);
                            markersOverlay.Markers.Add(m);
                        }
                    })),
        // GMarkerGoogleType.green);
                           // GMarkerGoogle m = new GMarkerGoogle(gMapControl1.Position, GMarkerGoogleType.green_pushpin);
                            markersOverlay.Markers.Add(m);
                        }
                    }
Coordinator
Jul 2, 2013 at 1:12 PM
GMapOverlay markersOverlay = new GMapOverlay("VCS MAP");
map.Overlays.Add(markersOverlay);

check the demo for more..
Jul 2, 2013 at 1:23 PM
Thanks for the quick reply but my error
shows here
var Latitude = float.Parse((dataGridView1.Columns[0].ToString()), CultureInfo.InvariantCulture);
 var Longitude = float.Parse((dataGridView1.Columns[1].ToString()), CultureInfo.InvariantCulture);
Coordinator
Jul 2, 2013 at 1:36 PM
what error ;/
Jul 2, 2013 at 2:06 PM
I get an error as "input string was not in correct format ".
Coordinator
Jul 2, 2013 at 2:12 PM
your current culture probably isn't Invariant
Jul 2, 2013 at 2:22 PM
Hi radioman,
Is there any way to sort this out I cant find any alternative to do that just need some help..
Coordinator
Jul 2, 2013 at 2:36 PM
remove ', CultureInfo.InvariantCulture'
Jul 2, 2013 at 2:45 PM
tried it still the same error..
Jul 3, 2013 at 8:02 AM
HI radioman,
You are the only one who can help me out I tried different ways to do but not to success.. Please help me
..
I am near completion of my project ..

iam stuck with this..i am newbie and really need some help..please tell me where i am going wrong.....
 if (comboBox5.SelectedIndex == 0)//(REGION 1)
            {


                String Query = " SELECT top  Latitude,Longitude  FROM[ICPS].[dbo].[Sheet3_kir]   ";

                SqlCommand cmdDatabase = new SqlCommand(Query, conDatabase);
                SqlDataReader myReader;
                gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
                GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;

                GMapOverlay markersOverlay = new GMapOverlay("VCS MAP");
                //gMapControl1.Overlays.Add(markersOverlay); 


                for (int i = 0; i <= dataGridView1.Rows.Count; i++)
                {
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        var Latitude = double.Parse(dataGridView1.Columns[1].ToString());
                        var Longitude = double.Parse(dataGridView1.Columns[2].ToString());
                        gMapControl1.Position = new PointLatLng(Latitude, Longitude);
                        // GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(float.Parse(this.dataGridView1.Columns[1].ToString), float.Parse(this.textBox26.Text)),
                        // GMarkerGoogleType.green);
                        GMarkerGoogle m = new GMarkerGoogle(gMapControl1.Position, GMarkerGoogleType.green_pushpin);
                        //markersOverlay.Markers.Add(m);
                    }
                }
Coordinator
Jul 3, 2013 at 8:40 AM
whats wrong?
Jul 3, 2013 at 8:51 AM
Input string was not in correct format.
#var Latitude = double.Parse(dataGridView1.Columns[1].ToString( ));
Coordinator
Jul 3, 2013 at 8:59 AM
so whats the string you are trying to parse?
Jul 3, 2013 at 9:06 AM
I have latitudes and longitudes in datagridview with column 1 and column 2 so when i click the combobox(region 1) it should select the top 10 long and lat and display it on gmapcontrol1.
Coordinator
Jul 3, 2013 at 9:57 AM
var x = dataGridView1.Columns[1].ToString( );
x = ?
Jul 3, 2013 at 10:26 AM
sorry for my stupid question as I am really new to this
but I am passing the latitude and longitude values from datagridview to var latitude and longitude
var Latitude = double.Parse(dataGridView1.Columns[1].ToString()); and then gmap1control recieves this latitude , longitudes and displays in mapcontrol
gMapControl1.Position = new PointLatLng(Latitude, Longitude);

so, where exactly the problem lies.... I really do not understand x=?
sorry for the stupid question....again....please
Coordinator
Jul 3, 2013 at 10:50 AM
what is the value of the x ?
Jul 3, 2013 at 11:05 AM
lat 56.4602
long -2.98
Coordinator
Jul 3, 2013 at 12:41 PM
then parse it with invariant culture
Jul 3, 2013 at 12:56 PM
thanks for the help radioman..


I have some null values in the lat and long columns when i load the datagrid view would that be the problem if it is how can i get rid of them
Jul 4, 2013 at 4:20 PM
Hi Radio man can you help me with this please
Coordinator
Jul 5, 2013 at 8:16 AM
just check if it's not null and then add it ;}
Jul 9, 2013 at 8:51 AM
Thanks radioman solved.
Sep 10, 2013 at 3:37 PM
Private Sub btnPlot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlot.Click
    myMap.Visible = True
    myMap.BringToFront()


    myMap.MapProvider = GoogleMapProvider.Instance
    'get tiles from server only
    myMap.Manager.Mode = AccessMode.ServerOnly
    'not use proxy
    GMapProvider.WebProxy = Nothing

    Dim overlayOne As New GMapOverlay("testone")
    myMap.Overlays.Add(overlayOne)
    myMap.SetCurrentPositionByKeywords("Camden,Australia")
    Dim i As Integer = 0

    For Each itm As ListViewItem In lstResults.Items
        Dim SR As SEARCH_RESULT = itm.Tag            
        Dim m As GMarkerGoogle = New GMarkerGoogle(New PointLatLng(SR.LATITUDE, SR.LONGITUDE), GMarkerGoogleType.green_pushpin)
        myMap.UpdateMarkerLocalPosition(m)
        overlayOne.Markers.Add(m)
    Next

    myMap.MinZoom = 1
    myMap.MaxZoom = 20
    'set zoom
    myMap.Zoom = CInt(NumericUpDown1.Value)
End Sub
This code is not working correctly. Can you guide me on this. There are more than 1200 lat and lon but only one is displayed in the map. Your help on this is highly appreciated.
Sep 10, 2013 at 3:38 PM
Thanks
Sep 10, 2013 at 3:39 PM
Also Kiran can you tell me how did you solve this problem.

Thanking you in advance
Roshan