Search code examples
iosobjective-ciphonegoogle-mapsgmsmapview

How can I check if a CLLocationCoordinate2D is inside four CLLocationCoordinate2D Square? in Objective C with Google Maps


I want to test if a CLLocationCoordinate2D is inside a Square created from other four CLLocationCoordinate2D

I have a struct like this:

typedef struct {
    CLLocationCoordinate2D southWest;
    CLLocationCoordinate2D southEast;
    CLLocationCoordinate2D northEast;
    CLLocationCoordinate2D northWest;
} Bounds;

And a CLLocationCoordinate2D coordinate passed as param. And I want to test if coordinate is inside the Bounds. How can I test that?

- (BOOL) isCoordinate:(CLLocationCoordinate2D)coordinate insideBounds:(Bounds)bounds { ... }

Solution

  • If you have four points you can make a CGRect and use CGRectContainsPoint()