Quote:
Originally Posted by coulls
Hi all,
I have a line object made up of two CLLocation's (startPoint and endPoint). I am adding a tolerance set in metres (say 3000 metres) around an MBR (Minimum Bounding Rectangle) derived from these two points.
The question I have is how would I add say 3000 metres to a CLLocation and arrive at a new CLLocation, especially given that there's no function like this?
Code:
-(CLLocation *) addDistanceToLocation:(CLLocation*)location:(float)metresLatitude:(float)metresLongitude;
What I'd ideally like to do is something like this:
Code:
startPoint = addDistanceToLocation:startPoint:3000:-3000
EDIT: I've changed my MBR code to read like this:
Code:
MBR *mbr = [MBR alloc];
CLLocation *x1y1 = [[CLLocation alloc] init];
CLLocation *x2y2 = [[CLLocation alloc] init];
x1y1.coordinate.latitude = MAX(startPoint.coordinate.latitude, [endPoint.coordinate.latitude]);
x1y1.coordinate.longitude = MIN(startPoint.coordinate.longitude, [endPoint.coordinate.longitude]);
x2y2.coordinate.latitude = MIN(startPoint.coordinate.latitude, [endPoint.coordinate.latitude]);
x2y2.coordinate.longitude = MAX(startPoint.coordinate.longitude, [endPoint.coordinate.longitude]);
mbr.topLeft = x1y1;
mbr.bottomRight = x2y2;
Thought it might be easier to work with two CLLocations (topLeft and bottomRight). Still can't see how to add distances to these and arrive at a new set of points.
Thanks,
Jason
|
I wrestled with this too. You can't change the values in a CLLocation. What you have to do is calculate the new coordinate you want, and then initialize a new one with the parameters from the old one.
You use the call initWithCoordinate:altitude:horizontalAccuracy:ver ticalAccuracy:timestamp: to create a new location using the values from the old location.
That lets you copy most, but not all, of the settings from the old location.
Regards,
Duncan C
WareTo