Can any trig or GPS experts help me out here? I\'m trying to create a geo-spacial bounding box (rectangle) calculation returning the maximum latitude and longitude using the
I haven't looked at your code, but you could also use the MapKit function MKCoordinateRegionMakeWithDistance() to have the framework calculate a bounding box for you.
CLLocationCoordinate2D center = { 37.3, -122.0 };
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 2000.0, 2000.0);
CLLocationCoordinate2D northWestCorner, southEastCorner;
northWestCorner.latitude = center.latitude - (region.span.latitudeDelta / 2.0);
northWestCorner.longitude = center.longitude + (region.span.longitudeDelta / 2.0);
southEastCorner.latitude = center.latitude + (region.span.latitudeDelta / 2.0);
southEastCorner.longitude = center.longitude - (region.span.longitudeDelta / 2.0);
How are you guys setting up the NSPredicates?
I seem to run into performance issues with mine.
NSPredicate *northWestLat = [NSPredicate predicateWithFormat:@"ANY locations.lat > %lf", northWestCorner.latitude];
NSPredicate *southhWestLat = [NSPredicate predicateWithFormat:@"ANY locations.lat < %lf", southEastCorner.latitude];
NSPredicate *latitudePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:northWestLat, southhWestLat, nil]];
NSPredicate *northWestLng = [NSPredicate predicateWithFormat:@"ANY locations.lng < %lf", northWestCorner.longitude];
NSPredicate *southEastLng = [NSPredicate predicateWithFormat:@"ANY locations.lng > %lf", southEastCorner.longitude];
NSPredicate *longitudePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:northWestLng, southEastLng, nil]];
NSPredicate *coordPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:latitudePredicate, longitudePredicate, nil]];
CLLocationCoordinate2D stores coordinates in degrees, but the trig functions you're using require radian units. If you convert to radians (multiply by M_PI/180, or 0.017453293f), it will probably work.