Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to plot custom markers on lat-lon points read from a csv file

But I am not able to get my code to work: it either adds just the first marker or the last

Could you please have a look and tell me where i am getting it wrong?

   markers = new GMapOverlay("markers");
                 while ((line = sr.ReadLine()) != null)
                {
                    string[] parts = line.Split(',');
                    var p = parts;
                    Double.TryParse(parts[3],out lat);
                    Double.TryParse(parts[4], out lon);
                    GMapMarker marker = new GMarkerGoogle(new PointLatLng(lat, lon), new Bitmap("..\\..\\Resources\\arp.jpg"));
                    
                    marker.ToolTipText = new PointLatLng(lat,lon).ToString();
                     
                    marker.IsVisible = true;

                    markers.Markers.Add(marker);
                    navDataMap.Overlays.Add(markers);

 

                }

//adds just first marker

                markers = new GMapOverlay("markers");
                 while ((line = sr.ReadLine()) != null)
                {
                    string[] parts = line.Split(',');
                    var p = parts;
                    Double.TryParse(parts[3],out lat);
                    Double.TryParse(parts[4], out lon);
                    GMapMarker marker = new GMarkerGoogle(new PointLatLng(lat, lon), new Bitmap("..\\..\\Resources\\arp.jpg"));
                    
                    marker.ToolTipText = new PointLatLng(lat,lon).ToString();
                     
                    marker.IsVisible = true;

                    markers.Markers.Add(marker);
                    //navDataMap.Overlays.Add(markers);

 

                }
                navDataMap.Overlays.Add(markers);

//adds just last marker

Thank you


What I have tried:

all the stackoverflow solutions
Posted
Updated 29-Nov-18 9:35am

1 solution

All you have to do is debug your code. Step through it line by line and see what is happening. We can't run your code so we can't do this for you. And we shouldn't. Debugging code is the most important tool a developer can have.

If it is only adding 1 then your loop is likely not working. But only you can figure out why since we can't run your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900