Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's how I recommend doing it: </p> <p>Store lat/long in a dictionary and fire them off as strings bundled in a notification. Setup an observer in the application delegate and have the callback function store the lat/long in class properties of the application delegate and/or store them in the application defaults. </p> <p>In your class where you acquire the coordinates:</p> <pre><code>- (void)locationUpdate:(CLLocation *)location { NSString *locationString, *locLat, *locLong; locationString = [location description]; locLat = [NSString stringWithFormat:@"%lf", location.coordinate.latitude]; locLong = [NSString stringWithFormat:@"%lf", location.coordinate.longitude]; NSDictionary *locationDictionary = [NSDictionary dictionaryWithObjectsAndKeys:locationString, @"description", locLat, @"latitude", locLong, @"longitude", nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"updateSearchLocation" object:self userInfo:locationDictionary]; } </code></pre> <p>In your application delegate class:</p> <pre><code>- (void)applicationDidFinishLaunching:(UIApplication *)application { // Listen for search coordinates broadcast [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setCoordinates:) name:@"updateSearchLocation" object:nil]; } - (void)setCoordinates:(id)sender { self.latitude = [[sender userInfo] objectForKey:@"latitude"]; self.longitude = [[sender userInfo] objectForKey:@"longitude"]; NSLog(@"location = %@", [[sender userInfo] objectForKey:@"description"]); } </code></pre> <p>Dont forget to setup the class properties in the application delegate header file as NSString. You can then access the coordinates by calling directly from the application delegate: </p> <pre><code>YourAppDelegateClassName *appDelegate = [[UIApplication sharedApplication] delegate]; NSLog(@"lat = %@, long = %@", appDelegate.latitude, appDelegate.longitude); </code></pre> <p>Or you can access them anywhere from the user defaults:</p> <pre><code>[[NSUserDefaults standardUserDefaults] objectForKey:@"latitude"]; [[NSUserDefaults standardUserDefaults] objectForKey:@"longitude"]; </code></pre> <p>I hope that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload