I want to show something like a path for arrays containing longitudes and latitudes in a C# windosform application. I am using the GMap.NET.WindowsForms Nuget package. I used the following code, but it marks the last one. Actually it shows the previous points too, but it refreshes to the next one until getting the final one.
double[] lats = { 10, 50, 60 };
double[] longs = { 40, 25, 10 };
int i = 0;
var markersOverlay = new GMap.NET.WindowsForms.GMapOverlay("marker1");
var marker = new GMap.NET.WindowsForms.Markers.GMarkerGoogle(
new PointLatLng(Convert.ToDouble(latitude.Text), Convert.ToDouble(longitude.Text)),
GMap.NET.WindowsForms.Markers.GMarkerGoogleType.red_small);
markersOverlay.Markers.Add(marker);
gmap.Overlays.Add(markersOverlay);
foreach (var lat in lats)
{
MessageBox.Show($"{lat} , {longs[i]}");
gmap.Position = new PointLatLng(lat, longs[i]);
i++;
}
gmap.Zoom = Convert.ToDouble(zoom_level.Text);
gmap.Update();
gmap.Refresh();
How may I show all the specified lats and longs on the map?
It seems you are trying to draw a route based on some coordinations. To draw a path on map you should create an overlay layer for it and then add create a route from coordinations and add it to this ovaerlay. A possible solution is like this:
UPDATE 1: Adding text to route segments using transparent marker with display-always tooltip
UPDATE 2: Using precise formula to calculating midpoints.
Using a simple average approach to calc midpoint as in flat geometry on a spherical surface is not accurate (as in update 1 to set midpoint markers).
In this update the precise formula is applied from Calculate distance, bearing and more between Latitude/Longitude points to calculate midpoints.
As the image shows, midpoints are still not exactly on the route. This might be due to slightly distortion of earth from perfect sphere.
A solution is to add more intermediate point in route (using MidPoint function) and put markers at these points, which also tends to more precise route.