CLLocation, what am I doing wrong?

Discussion in 'iOS Programming' started by detz, Aug 11, 2008.

  1. detz macrumors 65816

    Joined:
    Jun 29, 2007
    #1
    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);
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    CLLocationDistance is a double:
    Code:
    NSLog(@"Distance %@ %@ [b][color=red]%f[/color][/b]",location1,location2,distance);
     

Share This Page