How to check is a point (marker) in some area or not?

Topics: Windows Forms
Nov 5, 2012 at 5:59 PM
Edited Feb 17, 2013 at 11:07 PM
At first, BIG thanks everyone on this GreatMap project, especially radioman!!!
I have two question:

1). How check is marker (my current location from gps) in some specify circle or square area?
To explain, I want to check is car on marked parking or not. Parking can be a another marker (10m radius) or square polygon Image1

2). How remove blue cross from map control? Image2

Regards.
Nov 5, 2012 at 6:11 PM

if(map.MapProvider.Projection.GetDistance < X) { ..

..you use debug build, so you get the blue cross for debugging, in release build there is red center marker, you can turn it off too, map.ShowCenter = false;

Nov 5, 2012 at 6:56 PM
Edited Nov 5, 2012 at 7:22 PM

Many THANKS radioman for quick answer, works like a charm ;)

Feb 16, 2013 at 2:00 PM
To check if is inside a polygon you can use below code; call it with desired point and a list containing polyngon points (always using Lat/Long coordinates) and will be returned a bool result indicanting if it is inside or not.

ask if you have any dificult :
  public bool FindPoint(double pointLat, double pointLng, List<PointLatLng> PontosPolig)
    {//                             X               y               
        int sides = PontosPolig.Count();
        int j = sides - 1;
        bool pointStatus = false;

        for (int i = 0; i < sides; i++)
        {
            if (PontosPolig[i].Lng < pointLng && PontosPolig[j].Lng >= pointLng ||
                PontosPolig[j].Lng < pointLng && PontosPolig[i].Lng >= pointLng)
            {
                if (PontosPolig[i].Lat + (pointLng - PontosPolig[i].Lng) /
                    (PontosPolig[j].Lng - PontosPolig[i].Lng) * (PontosPolig[j].Lat - PontosPolig[i].Lat) < pointLat)
                {
                    pointStatus = !pointStatus;
                }
            }
            j = i;
        }
        return pointStatus;
    }
regards,

marcelo
Apr 3, 2013 at 7:17 PM
How does it work? Is sorting or Clock-wise-ness required?
Is it on wikipedia or such??
I just ran it and it seems too good to be true.

        static void Main(string[] args)
        {
            List<PointLatLng> PontosPolig = new List<PointLatLng>();

            PointLatLng p1 = new PointLatLng(0, 0);
            PointLatLng p2 = new PointLatLng(2, 0);
            PointLatLng p3 = new PointLatLng(2, 2);
            PointLatLng p4 = new PointLatLng(0, 2);

            PontosPolig.Add(p1);
            PontosPolig.Add(p2);
            PontosPolig.Add(p3);
            PontosPolig.Add(p4);

            bool retval = false;

            retval= FindPoint(1.0, 1.0, PontosPolig);
            retval = FindPoint(10.0, 10.0, PontosPolig);
            retval = FindPoint(0.0, 0.0, PontosPolig);
            retval = FindPoint(-1.0, -1.0, PontosPolig);

            retval = FindPoint(2.01, 1.0, PontosPolig);
            retval = FindPoint(1.0, 2.01, PontosPolig);

            retval = FindPoint(0.7, 0.7, PontosPolig);
            retval = FindPoint(0.01, 0.01, PontosPolig);
            retval = FindPoint(1.99, 1.99, PontosPolig);
            retval = FindPoint(0.001, 1.999, PontosPolig);

            retval = FindPoint(1.0, 2.01, PontosPolig);
        }

        public static bool FindPoint(double pointLat, double pointLng, List<PointLatLng> PontosPolig)
        {//                             X               y               
            int sides = PontosPolig.Count();
            int j = sides - 1;
            bool pointStatus = false;

            for (int i = 0; i < sides; i++)
            {
                if (PontosPolig[i].Lng < pointLng && PontosPolig[j].Lng >= pointLng ||
                    PontosPolig[j].Lng < pointLng && PontosPolig[i].Lng >= pointLng)
                {
                    if (PontosPolig[i].Lat + (pointLng - PontosPolig[i].Lng) /
                        (PontosPolig[j].Lng - PontosPolig[i].Lng) * (PontosPolig[j].Lat - PontosPolig[i].Lat) < pointLat)
                    {
                        pointStatus = !pointStatus;
                    }
                }
                j = i;
            }
            return pointStatus;
        }




    }
}
Apr 4, 2013 at 2:58 PM
p.s. check GMapPolygon.IsInside