Advertisement
Guest User

Untitled

a guest
May 27th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. // didUpdateToLocation is deprecated, replaced with didUpdateToLocations with an array
  2. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
  3.  
  4. // code in case I need to get more than one location
  5. int objCount = [locations count];
  6. NSLog(@"MapVC: Delegate: didUpdateLocationS - objects count = %u", objCount);
  7.  
  8. if (objCount > 1) {
  9. CLLocation *oldLocation = [locations objectAtIndex:objCount - 1];
  10. NSLog(@"Prior location %f,%f", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
  11. }
  12.  
  13. CLLocation *newLocation = [locations lastObject];
  14. self.currentLocation = newLocation;
  15.  
  16. if(newLocation.horizontalAccuracy <= 1000.0f){
  17.  
  18. [self.locationManager stopUpdatingLocation];
  19. }
  20.  
  21. CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
  22. [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  23.  
  24. if (error){
  25.  
  26. NSLog(@"Geocode failed with error: %@", error);
  27.  
  28. return;
  29. }
  30.  
  31. NSString * location = ([placemarks count] > 0) ? [[placemarks objectAtIndex:0] locality] : @"Not Found";
  32. NSLog(@"=> reverseGeo Location: %@", location);
  33.  
  34. // get the CLPlacemark object created by the CLGeocoder
  35. CLPlacemark *myPlacemark = [placemarks objectAtIndex:0];
  36. NSString *adminArea = myPlacemark.administrativeArea;
  37.  
  38. NSString *countryCode = myPlacemark.ISOcountryCode;
  39. NSString *countryName = myPlacemark.country;
  40. NSString *subAdmin = myPlacemark.subAdministrativeArea;
  41. NSString *city = myPlacemark.locality;
  42.  
  43. NSLog(@"My country code: %@ and countryName: %@ and adminArea: %@ and subAdmin: %@ andCity: %@", countryCode, countryName, adminArea, subAdmin, city);
  44.  
  45. // call custom helper method to determine which row of the state array we are working with
  46. [self setupFromReverseGeocodedLocation:adminArea];
  47.  
  48. }];
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement