4

Hi I have 1000 latitudes , longitudes and want to display all of them on maps . I tried several ways to do it but not luck.....I have a datagridview which has client,lat,long,region. each client has a region.I have a combobox when I click on combobox region 1 it should display all clients on region 1 on map can it be possible. please help.

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);
        }
    }
default locale
  • 13,035
  • 13
  • 56
  • 62
kiran v
  • 137
  • 1
  • 4
  • 13
  • 1
    `I tried several ways to do it but not luck.....` Please describe what exactly is going wrong – default locale Jul 03 '13 at 11:45
  • I nput string was not in correct format. var Latitude = double.Parse(dataGridView1.Columns[1].ToString( )); – kiran v Jul 03 '13 at 11:47
  • This problem has nothing to do with gmap.net and maps in general. Check out this string (print it out, or look it up in debugger session): `dataGridView1.Columns[1].ToString( )`. Runtime is trying to say that this string is not a valid double value. – default locale Jul 03 '13 at 11:50
  • i am struck with point from last 2 days but dont know what to do with this statment. – kiran v Jul 03 '13 at 12:04
  • Just output this string. Or make sure that you have properly formatted values in `Latitude` column of `[ICPS].[dbo].[Sheet3_kir]` table – default locale Jul 03 '13 at 12:06
  • I have checked them the output was fine and latitude column is also float in the table. – kiran v Jul 03 '13 at 12:25
  • It's impossible to help you without knowing what is getting passed to `double.Parse` method. Output the value of `dataGridView1.Columns[1].ToString( )` and see which value gave you a problem. BTW, where do you populate `dataGridView1`? – default locale Jul 03 '13 at 12:31
  • I have a load method to populate the datagridview1. – kiran v Jul 03 '13 at 12:39
  • 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 – kiran v Jul 03 '13 at 12:47
  • Thanks for the response now it gives an another error. 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index' – kiran v Jul 03 '13 at 13:42
  • Thanks Default now its been solved..... – kiran v Jul 08 '13 at 14:41
  • The error lies in the lat/long list. – kiran v Jul 08 '13 at 14:42
  • my 5 to you default locale...solved. – kiran v Jul 09 '13 at 08:32

2 Answers2

0
            MySqlDataAdapter da = new MySqlDataAdapter("select * from sinkhole where sinkhole_status = '" + "Active" + "'", Conn);
            MySqlCommandBuilder cBuilder = new MySqlCommandBuilder(da);

            DataTable dataTable = new DataTable();
            DataSet ds = new DataSet();
            da.Fill(dataTable);

            for (int i = dataTable.Rows.Count - 1; i >= 0; i--)
            {
                double lng = double.Parse(dataTable.Rows[i][4].ToString());
                double lat = double.Parse(dataTable.Rows[i][3].ToString());
                string location = dataTable.Rows[i][2].ToString();
                string name = dataTable.Rows[i][1].ToString();
                string desciption = dataTable.Rows[i][5].ToString();

                GMapOverlay markersOverlay = new GMapOverlay(map, "marker");
                GMapMarkerGoogleGreen marker = new GMapMarkerGoogleGreen(new PointLatLng(lat, lng));
                markersOverlay.Markers.Add(marker);
                //marker.ToolTipMode = MarkerTooltipMode.Always;
                marker.ToolTip = new GMapRoundedToolTip(marker);
                marker.ToolTipText = "Coordinates: (" + Convert.ToString(lat) + "," + Convert.ToString(lng) + ")" + "\nLocation: " + location + "\nName: " + name;
                map.Overlays.Add(markersOverlay);
0
 for (int i = 0; i < dataGridView1.Rows.Count; ++i)
      {
        double lat = Convert.ToDouble(dataGridView1.Rows[i].Cells[9].Value) ; 
        double    lng = Convert.ToDouble(dataGridView1.Rows[i].Cells[10].Value);
           string Vehicle = Convert.ToString(dataGridView1.Rows[i].Cells[5].Value);
           string name = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);
        string   Adress = Convert.ToString(dataGridView1.Rows[i].Cells[2].Value);

            MapaContr.MapProvider = GMapProviders.GoogleHybridMap;

            GMapOverlay markersOverlay = new GMapOverlay("markers");
            GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(lat, lng), GMarkerGoogleType.lightblue);
            markersOverlay.Markers.Add(marker);
           marker.ToolTipMode = MarkerTooltipMode.Always;
            marker.ToolTip = new GMapRoundedToolTip(marker);
            marker.ToolTipText =  "Adress: " + Adress + "\nIme: " + name + "\nVehicle:" + Vehicle   ;
            MapaContr.Overlays.Add(markersOverlay);

I am made solution for multiple markers on Gmap from MySql data base and datagridView(dataGridView1) solution. Its very precision and easy to manage.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 01 '22 at 00:08