Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Latitude Longitude IOS 4.3
  2. - (void)viewDidLoad {
  3.  [super viewDidLoad];
  4. locationManager = [[CLLocationManager alloc] init];
  5. locationManager.delegate = self;
  6. [locationManager startUpdatingLocation];
  7.  
  8. }
  9.  
  10.  
  11. - (void)locationManager:(CLLocationManager *)manager
  12. didUpdateToLocation:(CLLocation *)newLocation
  13.        fromLocation:(CLLocation *)oldLocation
  14. {
  15.  
  16. int degrees = newLocation.coordinate.latitude;
  17. double decimal = fabs(newLocation.coordinate.latitude - degrees);
  18. int minutes = decimal * 60;
  19. double seconds = decimal * 3600 - minutes * 60;
  20. NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f"",
  21.                  degrees, minutes, seconds];
  22. //latLabel.text = lat;
  23. degrees = newLocation.coordinate.longitude;
  24. decimal = fabs(newLocation.coordinate.longitude - degrees);
  25. minutes = decimal * 60;
  26. seconds = decimal * 3600 - minutes * 60;
  27. NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f"",
  28.                    degrees, minutes, seconds];  
  29. NSLog(@"%@ %@",longt, lat);
  30.  
  31. }
  32.        
  33. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
  34. {
  35. NSLog(@"GPS Error: %@", [error localizedDescription]);
  36. }