display route - problem

Topics: Windows Forms
Mar 19, 2012 at 11:32 PM
Edited Mar 19, 2012 at 11:32 PM

Hi,

i am trying to display route of points, but routes it's not display correctly

my code:

 

                List<PointLatLng> points = new List<PointLatLng>();

                foreach (Trace trace in traces)
                {
                    PointLatLng p = new PointLatLng(trace.Latitude, trace.Longitude);

                    points.Add(p);
                }

                GMapRoute route = new GMapRoute(points, "route");
                Pen pen=new Pen(Color.Red);
                pen.Width=2;
                route.Stroke = pen;
                mapRoutes.Routes.Add(route);
                map1.ZoomAndCenterRoute(route);

 

 

Sample of problem

Mar 20, 2012 at 7:54 AM

so whats the 'problem'?

Mar 20, 2012 at 11:37 AM

I want to display route over the road and not over the air. I know that this is possible, it's works a while ago :/

Mar 20, 2012 at 11:43 AM

use routing provider from google or openstreet, check the demos

Mar 20, 2012 at 8:29 PM

I try this code in demo project and it's work.

                PointLatLng start = new PointLatLng(46.3716717, 15.8289350);
                PointLatLng end = new PointLatLng(46.3810850, 15.8457600);
                MapRoute route = GMapProviders.GoogleMap.GetRoute(start, end, false, false, 10);
                GMapRoute r = new GMapRoute(route.Points, "test");
But when I try in my project it's not work, because route is null.

Any ideas, what could be wrong ?

Mar 20, 2012 at 9:29 PM

only for google?

Mar 20, 2012 at 10:17 PM
Edited Mar 20, 2012 at 10:27 PM

no, also for else. It seems that function List<PointLatLng> GetRoutePoints not give me expected points.

Could not load file or assembly 'System.Data.SQLite, Version=1.0.79.0......

Seems my fault.

Mar 20, 2012 at 10:54 PM

Ok, now works but route is still out of the road :/

Sample

Mar 21, 2012 at 11:08 AM

Problem solved.

MapRoute route = GMapProviders.GoogleMap.GetRoute(start, end, false, false, 15);
Mar 30, 2012 at 9:44 PM

Hi nemonemo,
How do you use your points list you create in your first code, in GetRoute

it seems it only use start and end points?

May 8, 2012 at 11:13 AM
Edited May 8, 2012 at 11:14 AM
nemonemo wrote:

Hi,

i am trying to display route of points, but routes it's not display correctly

my code:

 

                List<PointLatLng> points = new List<PointLatLng>();

                foreach (Trace trace in traces)
                {
                    PointLatLng p = new PointLatLng(trace.Latitude, trace.Longitude);

                    points.Add(p);
                }

                GMapRoute route = new GMapRoute(points, "route");
                Pen pen=new Pen(Color.Red);
                pen.Width=2;
                route.Stroke = pen;
                mapRoutes.Routes.Add(route);
                map1.ZoomAndCenterRoute(route);

 

 

Sample of problem

 

im also trying to route. i took your code, but i didnt recognize, where mapRoutes (mapRoutes.Routes.Add(route)) come from!?

my code:
            List<PointLatLng> points = new List<PointLatLng>();

            int count = 0;
            int count1 = 0;

            map.RoutesEnabled = true;

            map.MapProvider = GMapProviders.GoogleMap;

            foreach (double item in lx1)
            {
                if (count1 ==5)
                {
                    PointLatLng p = new PointLatLng(item, ly1[count]);
                    points.Add(p);
                    count1 = 0;
                }
                count++;
                count1++;
            }

            GMapRoute route = new GMapRoute(points, "route");
            Pen pen = new Pen(Color.Red);
            pen.Width = 2;
            route.Stroke = pen;
            map.ZoomAndCenterRoute(route);

p.s: its my first time, working with this stuff...
May 8, 2012 at 11:43 AM
  • mapRoutes is overlay, you have to add it to map.Overlays on start somwhere
  • don't initialize Pen pen=new Pen(Color.Red); but simply use route.Stroke.XX directly, otherwise you'll have memory leak