How to display routes on OpenStreetMaps from richtextbox data, how create list which two value from another array?

StackOverflow https://stackoverflow.com/questions/22975490

Question

I have this function which get back longitude and latitude from my Rtb data (first picture):

// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
    private Tuple<double, double>[] wsp_geograficzne(string[] lines)
    {
        return Array.ConvertAll(lines, line =>
        {
            string[] elems = line.Split(',');
            return new Tuple<double, double>(0.01*double.Parse(elems[1]), 0.01*double.Parse(elems[3]));
        });
    }

rtb data

This line calls this above function:

var data = wsp_geograficzne(richTextBox1.Lines);

This is a sample, which display routes on my OpenStreetMaps.

                    GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");// Constructing object for Overlay
                    gMapControl1.Overlays.Add(routes);

                    List<PointLatLng> list = new List<PointLatLng>(); // The list of Coordinates to be plotted
                    list.Add(new PointLatLng(53.119149707703, 23.1447064876556));
                    list.Add(new PointLatLng(53.11963262556597, 23.1468522548676));
                    list.Add(new PointLatLng(53.1205276192621, 23.1460046768188));
                    list.Add(new PointLatLng(53.120701464779, 23.1463050842285));
                    list.Add(new PointLatLng(53.1200962217943, 23.1489872932434));
                    list.Add(new PointLatLng(53.1196970143107, 23.1489014625549));
                    list.Add(new PointLatLng(53.119439459128, 23.1490087509155));

                    GMapRoute r = new GMapRoute(list, "myroute"); // object for routing
                    r.Stroke.Width = 5;
                    r.Stroke.Color = Color.Blue;
                    routes.Routes.Add(r);
                    gMapControl1.ZoomAndCenterRoute(r);
                    gMapControl1.Zoom = 15;

It looks like on the picture: dispaly routes on OpenStreetMap

I want display routes from my data "wsp_geograficzne" (wsp_geograficzne include longitude and latitude) on this map. How should I do it? Is there any method that allow me to create List which data from "wsp_geograficzne"? I trying something like this:

List<PointLatLng> nowa = new List<PointLatLng>();
                   foreach (var p in data)
                   nowa.Add(p.Item1, p.Item2);

but it dont works. I get back error: Error 2 No overload for method 'Add' takes 2 arguments.

Please help :)

Was it helpful?

Solution

Ok I find answer (new function which get back 2 value (longitude and latitude) from rtb (longitude and latitude are back in decimal notation):

// funkcja pobierająca szerokość i długość geograficzną w formacie dziesiętnym
    private Tuple<double, double>[] wsp_geograficzne(string[] lines)
    {
        return Array.ConvertAll(lines, line =>
        {
            string[] elems = line.Split(',');

            double we1 = 0.01 * double.Parse(elems[3], EnglishCulture);
            int stopnie1 = (int)we1;
            double minuty1 = ((we1 - stopnie1) * 100) / 60;
            double szerokosc_dziesietna = stopnie1 + minuty1;

            double we2 = 0.01 * double.Parse(elems[5], EnglishCulture);
            int stopnie2 = (int)we2;
            double minuty2 = ((we2 - stopnie2) * 100) / 60;
            double dlugosc_dziesietna = stopnie2 + minuty2;

            return new Tuple<double, double>(szerokosc_dziesietna, dlugosc_dziesietna);
        });
    }

And this is a part which display routes on the map.

{
                    var data = wsp_geograficzne(richTextBox1.Lines);

                    List<PointLatLng> nowa = new List<PointLatLng>();
                    foreach (var p in data)
                    nowa.Add(new PointLatLng(p.Item1, p.Item2));

                    GMapOverlay routes = new GMapOverlay(gMapControl1, "routes");
                    gMapControl1.Overlays.Add(routes);

                    GMapRoute r = new GMapRoute(nowa, "myroute"); // object for routing
                    r.Stroke.Width = 9;
                    r.Stroke.Color = Color.Blue;
                    routes.Routes.Add(r);
                    gMapControl1.ZoomAndCenterRoute(r);
                    gMapControl1.Zoom = 16;

                }

If someone has another notations this part:

List<PointLatLng> nowa = new List<PointLatLng>();
                    foreach (var p in data)
                    nowa.Add(new PointLatLng(p.Item1, p.Item2));

please show me here.

Greetings from Poland :).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top