Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to access NSArray object that contains CLLocation information
    primarykey
    data
    text
    <p>I am new to objective-c and have been trying to work on this problem for the past 2 and a half hours. So far I was able to have some success and my app can start searching for the user's location as soon as the app is launched.</p> <p>I then setup a delegate for <code>CLLocationManager</code> based off of this advice:</p> <p>"Add the syntax to declare that this class (the ViewController.h/m) is adopting this particular protocol. By default, any other classes that create an instance of this class will also automatically adopt the protocol.</p> <pre><code>@interface ViewController : UIViewController &lt;CLLocationManagerDelegate&gt; </code></pre> <p>The line of code listed above shows the syntax used to show ViewController adopts the CLLocationManagerDelegate protocol. We simply add it between angled brackets &lt;> in the @interface line in the header."</p> <p>So I successfully added the above line inside my ViewController.m and ViewController.h file, and then I also followed that same tutorials advice of:</p> <p>"The full method is: </p> <pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations </code></pre> <p>and when implemented it tells the delegate that new location data is available. We have two arguments on this method. The first lets you know which CLLocationManager provided the update and the last provides the CLLocation information which is stored in an NSArray."</p> <p>Below is all of my <code>ViewController.h</code> code and then next wll be my ViewController.m code:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;CoreLocation/CoreLocation.h&gt; @interface ViewController : UIViewController &lt;CLLocationManagerDelegate&gt; @property (nonatomic, strong) IBOutlet UILabel *gpsLabel; -(IBAction)gpsButton; @end </code></pre> <p>Here is my ViewController.m code:</p> <pre><code>#import "ViewController.h" #import &lt;CoreLocation/CoreLocation.h&gt; @interface ViewController () &lt;CLLocationManagerDelegate&gt; @property (nonatomic, strong) CLLocationManager * gpsLM; -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.gpsLM = [[CLLocationManager alloc]init]; [self.gpsLM startUpdatingLocation]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(IBAction)gpsButton{ } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { } @end </code></pre> <p>I am confused on where to go from here. Assuming I am even doing everything correctly so far(am I?), then how do I access the location data that has been stored in the NSArray object called locations?</p> <p>Thank you for the help.</p>
    singulars
    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.
 

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