mapping real-time GPS positioning data using dotspatial

Mar 2, 2011 at 7:41 PM

Dear all,

I am a beginner to use Dotspatial to develop my project.

It is so fantastic that I had used it for building serveral components successfully. Currently, I need to mapping real-time GPS positioning coordinates on the map windows (I had built a GPS components using for GPS setting and data receiving, a map component with simple GIS function used for displaying and enquire GPS trajectory). I need to use some function to REAL-TIME MAPPING on the map(like navigation). I successed now to read GPS data, but i donnot know how to continue the next step. anybody with experience tell me how to use Dotspatial to implement such function?

any helps could be appreciated.

Mar 24, 2011 at 10:44 AM

Hope the following code helps you and others out and gets you moving in the right direction.  First thing you'll want to do is in when you get a new gps position call map.Refresh() this will fire the Paint event which is where you'll want to put the code to show the gps position on the map this way it's done as the painting is being done so it's all smooth, add the Paint event to your map and code it like so:

private void map_Paint(object sender, PaintEventArgs e)
        {
            //if gps is enabled continue
            if (tsCmdGPS.Enabled && _GpsPos != null)
            {
                //draw an ellipse at the current gps position, using the PaintEventArgs
                Graphics g = e.Graphics;
                Pen pen = new Pen(Color.FromArgb(128, 255, 0, 0), 3); 
                //convert the gps position to map pixels
                Point ptGPSinPixels = map.ProjToPixel(new DotSpatial.Topology.Coordinate(_GpsPos.Longitude, _GpsPos.Latitude));
                g.DrawEllipse(pen, new Rectangle(ptGPSinPixels.X, ptGPSinPixels.Y, 20, 20));
                //if gps has moved off the map reposition map centering on gps position
                if (map.ViewExtents.MaxX < _GpsPos.Longitude || map.ViewExtents.MinX > _GpsPos.Longitude || map.ViewExtents.MaxY < _GpsPos.Latitude || map.ViewExtents.MinY > _GpsPos.Latitude)
                {
                    map.ViewExtents.SetCenter(_GpsPos.Longitude, _GpsPos.Latitude, map.ViewExtents.Width, map.ViewExtents.Height);
                }
            }
        }

Jan 14, 2013 at 6:10 AM

Update:

What CBiggerstaff create now needs to be modified to _GpsPos.Longitude.DecimalDegrees and _GpsPos.Latitude.DecimalDegrees

 

Problem:

When using Map.Paint, it will need rebuild paths of the map. If you have a ProgressHandler status bar hooked into your interface, you will "Building Paths..." over and over again.