1

I am using Geofencing. I want a method that checks whether or not a user is within certain boundaries.

I have the location as a CLLocationCoordinate2D which I've named location, and I have an array of 8 doubles, making up 4 coordinates (NW, NE, SW, SE). I can convert them to CLLocationCoordinate2D's. My question is, how can I check whether the location is within the boundaries? in iOS...

SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
  • Does the array of coordinates define some arbitrary polygon? [This](http://stackoverflow.com/questions/4354130/how-to-determine-if-an-annotation-is-inside-of-mkpolygonview-ios) may be useful including @capikaw's "map-less" version. –  Aug 18 '13 at 21:39
  • Geofences in iOS are `CLRegion` instances. The `CLRegion` class has a method `containsCoordinate` which takes in a `CLLocationCoordinate2D` and tells you if this coordinate is contained in the region. Currently `CLRegion` instances can only be circular and are defined by a center coordinate and a radius, so I am a little confused by your mentioning of an array of coordinates. – Jeff Ames Aug 19 '13 at 04:24
  • 1
    @theStreaker123 I assumed that his 8 doubles are 4 coordinates to make a rectangular bounding box (NW, NE, etc). – nevan king Aug 19 '13 at 08:39
  • @nevanking yes that is exactly what I meant. – SirRupertIII Aug 19 '13 at 15:11

1 Answers1

1

I don't think there's a built in method for this. You just check whether the location's latitude is less than the maximum boundary latitude and more than the minimum. Then the same with longitude.

If you convert them to MKMapPoint and MKMapRect, you can use MKMapRectContainsPoint() to check.

nevan king
  • 112,709
  • 45
  • 203
  • 241