code_junkie

Can the iPhone determine if you're facing north, south, east or west?

Nov 13th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. [[self delegate] currentDirectionLat:newLocation.coordinate.latitude Long:newLocation.coordinate.longitude];
  2.  
  3. -(void)currentDirectionLat:(float)latitude Long:(float)longitude
  4. {
  5. prevLongitude = currentLongitude;
  6. prevLatitude = currentLatitude;
  7.  
  8. currentLongitude = longitude;
  9. currentLatitude = latitude;
  10.  
  11. NSString *latDirection = @"";
  12. if (currentLatitude > prevLatitude)
  13. latDirection = @"N";
  14. else if (currentLatitude < prevLatitude)
  15. latDirection = @"S";
  16.  
  17. NSString *longDirection = @"";
  18. if (currentLongitude > prevLongitude)
  19. longDirection = @"E";
  20. else if (currentLongitude < prevLongitude)
  21. longDirection = @"W";
  22.  
  23. if ([longDirection length] > 0)
  24. [lblDirection setText:[NSString stringWithFormat:@"%@%@",latDirection,longDirection]];
  25. }
Add Comment
Please, Sign In to add comment