Ios to get the current geographic location
I want to help you with the following steps:
Prerequisites: CoreLocation. farme
# Import
Proxy
{
// Obtain the current geographic location: Step 1:
// These two variables: locationManaager is used to obtain the location, and checkinLocation is used to save the obtained Location Information
NSString * currentLatitude;
NSString * currentlongpolling;
CLLocationManager * locManager;
CLLocation * checkinLocation;
}
# Pragma mark -- CLLocationManagerDelegate
/*
Step 2:
Implement the first proxy method for geographic location
When you run this method, the locationManager has obtained the current location. Therefore, you should save the obtained location to the checkinLocation variable */
-(Void) locationManager :( CLLocationManager *) manager didUpdateToLocation :( CLLocation *) newLocation
FromLocation :( CLLocation *) oldLocation {
CheckinLocation = newLocation;
// Do something else
}
/*
Step 3:
The method implemented in step 2 is actually called by the method startUpdatingLocation in CLLocationManager. That is to say, when the program runs locationManager. startUpdatingLocation, the method implemented in step 2 will be called.
*/
-(Void) setupLocationManager {
LocationManager = [[CLLocationManageralloc] init];
If ([CLLocationManagerlocationServicesEnabled]) {
NSLog (@ "Starting CLLocationManager ");
LocationManager. delegate = self;
Location manager. distanceFilter = 200;
LocationManager. desiredAccuracy = kCLLocationAccuracyBest;
[LocationManagerstartUpdatingLocation];
} Else {
NSLog (@ "Cannot Starting CLLocationManager ");
/* Self. locationManager. delegate = self;
Self. locationManager. distanceFilter = 200;
LocationManager. desiredAccuracy = kCLLocationAccuracyBest;
[Self. locationManager startUpdatingLocation]; */
}
}