CoreLocation learning notes for iPhone development applications

Source: Internet
Author: User

IPhoneDeveloping applicationsCoreLocation locationLearning is the content to be introduced in this article. iPhone can useCoreLocationThe framework determines its physical location. Three technologies can be used to achieve this function: GPS, Wi-FiPositioningAnd cellular base station TinPositioning. But in the program, we only need to set the expected precision levelCoreLocationDecide which technology to use to better satisfy our requests.

1. Location Manager

 
 
  1. CLLocationManager * locationManager = [[CLLocationManager alloc] init]; // create a location manager
  2. LocationManager. delegate = self; // sets the proxy.
  3. LocationManager. desiredAccuracy = kCLLocationAccuracyBest; // specify the required precision level.
  4. LocationManager. distanceFilter = 1000.0f; // you can specify a distance filter.
  5. [LocationManager startUpdatingLocation]; // start Location Manager

2. Location Manager Proxy

There are two main proxy Methods

 
 
  1. // This method is called when the current position and position are determined to be updated
  2.  
  3. -(Void) locationManager :( CLLocationManager *) manager
  4. DidUpdateToLocation :( CLLocation *) newLocation
  5. FromLocation :( CLLocation *) oldLocation
  6. {
  7. NSString * latitudeString = [[NSString alloc] initWithFormat: @ "% g", newLocation. coordinate. latitude];
  8. // LatitudeLabel. text = latitudeString;
  9. [LatitudeString release];
  10. NSString * longitudeString = [[NSString alloc] initWithFormat: @ "% g", newLocation. coordinate. longpolling];
  11. // LongitudeLabel. text = longitudeString;
  12. [LongitudeString release];
  13. }
  14. // This method is called when an error occurs in location query.
  15.  
  16. (Void) locationManager :( CLLocationManager *) manager
  17. DidFailWithError :( NSError *) error
  18. {
  19. NSString * errorType = (error. code = kCLErrorDenied )?
  20. @ "Access Denied": @ "Unknown Error ";
  21. UIAlertView * alert = [[UIAlertView alloc]
  22. InitWithTitle: @ "Error getting Location"
  23. Message: errorType
  24. Delegate: nil
  25. CancelButtonTitle: @ "Okay"
  26. OtherButtonTitles: nil];
  27. [Alert show];
  28. [Alert release];
  29. }

Summary:IPhoneDeveloping applicationsCoreLocation locationI hope this article will be helpful to you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.