iOS Apple native System location Cllocationmanager

Source: Internet
Author: User

This is the first thing to do.

The following method is pro-Test available

------------------------------------------------------------

Dnlogfunc

// Initialize Location Management Objects

_locationmanager = [[cllocationmanager alloc] init];

// Request user Authorization

if ([[[[ uidevice currentdevice] systemversion] floatvalue] >= 8.0 ) {

[_locationmanager requestwheninuseauthorization];

}

// Specify the location proxy class

_locationmanager. Delegate = self;

_locationmanager. Distancefilter = +;

// turn on location services

[_locationmanager startupdatinglocation];

#pragma mark----cllocationmanagerdelegate

protocol method for locating a successful location update callback

-(void) Locationmanager: (cllocationmanager *) Manager didupdatelocations: (nsarray< cllocation *> *) Locations

{

cllocation *currentlocation = [Locations lastobject];

cllocationcoordinate2d coor = currentlocation. coordinate;

// dimension

dnlog(@ "coor.latitude==%f", coor.latitude);

// longitude

dnlog(@ "coor.longitude==%f", coor.longitude);

geo-coded classes

Clgeocoder *geocoder = [[Clgeocoder alloc] init];

anti-coding latitude and longitude points-- location information

[Geocoder reversegeocodelocation:[locations Lastobject] completionhandler:^ (Nsarray *placemarks, NSError *error) {

if (!error) {

take the last address

Clplacemark *placemark = [Placemarks lastobject];

NSString *citystr = [NSString stringwithformat:@ "%@", placemark.locality];

Dnlog (@ "citystr==%@", citystr); Remove Location City

Dnlog (@ "placemark==%@", placemark.addressdictionary);

Dnlog (@ "placemarks==%@", placemarks);

//

//        }

//    }];

}

iOS Apple native System location Cllocationmanager

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.