Ios to get the current geographic location

Source: Internet
Author: User

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]; */

}

}



Related Article

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.