2

I had userlocation and a boundary. And the boundary has 8 oordinates. I need to check wether the user is in the boundary or not. Am using mapview in iPhone.

Thanks in advance.

2 Answers2

3

A way to do this using some built-in functions in Map Kit are to add your boundary as an MKPolygon overlay to the map view. Keep a reference to the overlay as an ivar.

Then whenever you want to check if user is inside the boundary (for example when user's location changes), convert the user coordinates to a CGPoint and retrieve the CGPath for the boundary and call CGPathContainsPoint. There are Map Kit functions to do these conversions.

This previous answer of mine gives an example of how to add an MKPolygon overlay and this one has an example of the CGPathContainsPoint part.

Community
  • 1
  • 1
0

You can use the Point Inclusion in Polygon Test to check whether the users location is inside or outside the boundary (polygon).

Claus Broch
  • 9,212
  • 2
  • 29
  • 38