Posted By

rabc on 12/12/09


Tagged

location manager


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

davidsi
avanadra
bobbym245
sb
nsbuckner
davelb20
im3der
Tintenklecks


User location


 / Published in: Objective C
 

Search the user location and sets the administrativeArea

  1. // in viewDidLoad
  2. self.locationManager = [[CLLocationManager alloc] init];
  3. locationManager.delegate = self;
  4. locationManager.desiredAccuracy = kCLLocationAccuracyBest;
  5. [locationManager startUpdatingLocation];
  6.  
  7. // new methods
  8.  
  9.  
  10. // achou a localização
  11. - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
  12. {
  13. NSLog(@"Achou local");
  14.  
  15. [locationManager stopUpdatingLocation];
  16.  
  17. // this creates a MKReverseGeocoder to find a placemark using the found coordinates
  18. MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
  19. geoCoder.delegate = self;
  20. [geoCoder start];
  21. }
  22.  
  23.  
  24. // this delegate method is called if an error occurs in locating your current location
  25. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
  26. {
  27. NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);
  28. }
  29.  
  30.  
  31. - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
  32. NSLog(@"Problemas com o reverse geocoder");
  33.  
  34. }
  35.  
  36. - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
  37.  
  38. [someError show];
  39. [someError release];*/
  40.  
  41. self.location = [placemark administrativeArea];

Report this snippet  

You need to login to post a comment.