0

I have to show on a gmap control in c # more markers to make use of the code below.

The strange thing is that if I display only one marker is displayed correctly, while if I have more than one marker they are not displayed correctly ie the position is wrong ! How can I solve?

C: Code:

 private void buttonCarica_Click(object sender, EventArgs e)
        {
            if (comboBoxUtenti.Text != "")
            {
                MapControlRisorse.MapProvider = GMapProviders.GoogleMap;

                Utente utemp = new Utente(comboBoxUtenti.Text);
                MarcaTempo tm = new MarcaTempo(utemp);
                DataTable dt = tm.CaricaRisorsa(dateTimePickerDataRisorse.Value.Date);
                if (dt.Rows.Count == 0)
                {
                    MessageBox.Show("\n ATTENZIONE:  " + dateTimePickerDataRisorse.Value.Date);
                }
                else
                {
                    //int conta = 0;
                    GMapOverlay markersOverlay = new GMapOverlay("markers");
                    foreach (DataRow dr in dt.Rows)
                    {
                        Double lat = Convert.ToDouble(dr["Latitudine"].ToString());
                        Double lon = Convert.ToDouble(dr["Longitudine"].ToString());
                        MessageBox.Show("Lat: " + lat + " \n Lon: " + lon);
                        MapControlRisorse.Position = new GMap.NET.PointLatLng(lat, lon);
                        GMarkerGoogle marker = null;
                        GMarkerGoogleType markerType = new GMarkerGoogleType();
                        var point = new GMap.NET.PointLatLng(lat, lon);

                        //Verifico se l'utente ha segnato un ingresso o un uscita
                        //Se è entrato il marker sarà verde se è uscito sarà rosso
                        if (dr["Stato"].ToString() == "Ingresso")
                        {
                            markerType = GMarkerGoogleType.green;
                            // MapControlRisorse.Overlays.Add(markersOverlay);
                        }
                        else if (dr["Stato"].ToString() == "Uscita")
                        {
                            markerType = GMarkerGoogleType.red;

                            // MapControlRisorse.Overlays.Add(markersOverlay);
                        }
                        marker = new GMarkerGoogle(point, markerType);
                        marker.ToolTipText = "" + dr["Utente"].ToString();
                        markersOverlay.Markers.Add(marker);
                    }

                    MapControlRisorse.Overlays.Add(markersOverlay);
                    MapControlRisorse.MinZoom = 5;
                    MapControlRisorse.MaxZoom = 100;
                    MapControlRisorse.Zoom = 7;
                    MapControlRisorse.MouseWheelZoomEnabled = true;
                }
            }
        }

Image of Location:

enter code here

  • how are they in the wrong place? all together in a corner? slightly offset from each other? strangely attracted to each other? maybe you could add a image showing what's going on. – Ian Turton Jun 29 '18 at 10:46
  • I posted a picture cordinate I confirm that they are right: my cordinate are these (Italy) Lat: 44.49381 Lon: 11.33875, but apparently displayed in the Indian Ocean @IanTurton – riki Jun 29 '18 at 12:14
0

It looks like that point is at (44,11) rather than (11,44)

enter image description here

So I would suggest changing

var point = new GMap.NET.PointLatLng(lat, lon);

to

var point = new GMap.NET.PointLatLng(lon, lat);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.