Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

6. Core Location and Maps > 6.3. Pinpointing the Location of a Device

6.3. Pinpointing the Location of a Device

Problem

You want to find the latitude and longitude of a device.

Solution

Use the CLLocationManager class:

if ([CLLocationManager locationServicesEnabled]){
  self.myLocationManager = [[CLLocationManager alloc] init];
  self.myLocationManager.delegate = self;

  self.myLocationManager.purpose =
  @"To provide functionality based on user's current location.";

  [self.myLocationManager startUpdatingLocation];
} else {
  /* Location services are not enabled.
   Take appropriate action: for instance, prompt the
   user to enable the location services */
  NSLog(@"Location services are not enabled");
}

In this code, myLocationManager is a property of type CLLocationManager. The current class is also the delegate of the location manager in this sample code.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial