Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 { ... }
like image 701
Jimmy Avatar asked May 25 '15 07:05

Jimmy


1 Answers

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

like image 100
Carlos Pastor Avatar answered Sep 19 '22 13:09

Carlos Pastor