# question

## Check if lat/long point is inside polygons

`````` **Hi , I need help to Check if  array of lat/long point is inside polygons in map.**
``````

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,​

Welcome to our Microsoft Q&A platform!

`Xamarin.Forms.Maps` do not have this API to check the point is inside polygons, but we can judge it by ourselves. I refer to this thread, then I change it get following answer.

``````public bool IsPointInPolygon(Position p, Position[] polygon)
{
double minX = polygon.Latitude;
double maxX = polygon.Latitude;
double minY = polygon.Longitude;
double maxY = polygon.Longitude;
for (int i = 1; i < polygon.Length; i++)
{
Position q = polygon[i];
minX = Math.Min(q.Latitude, minX);
maxX = Math.Max(q.Latitude, maxX);
minY = Math.Min(q.Longitude, minY);
maxY = Math.Max(q.Longitude, maxY);
}

if (p.Latitude < minX || p.Latitude > maxX || p.Longitude < minY || p.Longitude > maxY)
{
return false;
}

// https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
bool inside = false;
for (int i = 0, j = polygon.Length - 1; i < polygon.Length; j = i++)
{
if ((polygon[i].Longitude > p.Longitude) != (polygon[j].Longitude > p.Longitude) &&
p.Latitude < (polygon[j].Latitude - polygon[i].Latitude) * (p.Longitude - polygon[i].Longitude) / (polygon[j].Longitude - polygon[i].Longitude) + polygon[i].Latitude)
{
inside = !inside;
}
}

return inside;
}``````

Best Regards,

Leon Lu