Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

detz

macrumors 65816
Original poster
Jun 29, 2007
1,051
0
This is driving me nuts, why wont this give me the correct distance?
Code:
NSDate *today = [NSDate date];
	
	CLLocationCoordinate2D ll1;
	CLLocationCoordinate2D ll2;
	
	ll1.latitude = 42.334131;
	ll1.longitude = -71.594403;
	
	ll2.latitude = 42.332789;
	ll2.longitude = -71.58848;
	
	CLLocation *location1 = [[CLLocation alloc] initWithCoordinate:ll1
														  altitude:1
												horizontalAccuracy:1 
											  verticalAccuracy:-1
														 timestamp:today];

	CLLocation *location2 = [[CLLocation alloc] initWithCoordinate:ll2 
														  altitude:1
												horizontalAccuracy:1 
											  verticalAccuracy:-1
														 timestamp:today];
	
	CLLocationDistance distance = [location2 getDistanceFrom:location1];
	NSLog(@"Distance %@ %@ %d",location1,location2,distance);
 
CLLocationDistance is a double:
Code:
NSLog(@"Distance %@ %@ [b][color=red]%f[/color][/b]",location1,location2,distance);
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.