Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-09-2010, 09:15 AM   #4 (permalink)
Duncan C
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 5,988
Duncan C has a spectacular aura about
Default You can't modify CLLocations - create another one instead.

Quote:
Originally Posted by coulls View Post
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
Duncan C is offline   Reply With Quote
 

» Advertisements
» Online Users: 651
18 members and 633 guests
24pfilms, Apptronics RBC, AragornSG, baja_yu, BrianSlick, cgokey, ChrisYates, clarky07, Clouds, dansparrow, EvilElf, gogoman, MAMN84, mapiko, nahmed, pipposanta, QuillGames, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,536
Threads: 94,052
Posts: 402,640
Top Poster: BrianSlick (7,979)
Welcome to our newest member, bppnormal11
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:17 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.