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
- CLLocationManager * locationManager = [[CLLocationManager alloc] init]; // create a location manager
- LocationManager. delegate = self; // sets the proxy.
- LocationManager. desiredAccuracy = kCLLocationAccuracyBest; // specify the required precision level.
- LocationManager. distanceFilter = 1000.0f; // you can specify a distance filter.
- [LocationManager startUpdatingLocation]; // start Location Manager
2. Location Manager Proxy
There are two main proxy Methods
- // This method is called when the current position and position are determined to be updated
-
- -(Void) locationManager :( CLLocationManager *) manager
- DidUpdateToLocation :( CLLocation *) newLocation
- FromLocation :( CLLocation *) oldLocation
- {
- NSString * latitudeString = [[NSString alloc] initWithFormat: @ "% g", newLocation. coordinate. latitude];
- // LatitudeLabel. text = latitudeString;
- [LatitudeString release];
- NSString * longitudeString = [[NSString alloc] initWithFormat: @ "% g", newLocation. coordinate. longpolling];
- // LongitudeLabel. text = longitudeString;
- [LongitudeString release];
- }
- // This method is called when an error occurs in location query.
-
- (Void) locationManager :( CLLocationManager *) manager
- DidFailWithError :( NSError *) error
- {
- NSString * errorType = (error. code = kCLErrorDenied )?
- @ "Access Denied": @ "Unknown Error ";
- UIAlertView * alert = [[UIAlertView alloc]
- InitWithTitle: @ "Error getting Location"
- Message: errorType
- Delegate: nil
- CancelButtonTitle: @ "Okay"
- OtherButtonTitles: nil];
- [Alert show];
- [Alert release];
- }
Summary:IPhoneDeveloping applicationsCoreLocation locationI hope this article will be helpful to you.