1. First import the Corelocation Framework Setup Agent
Cllocationmanagerdelegate
2.
-(void) Initlocationmanager
{
BOOL isenable = [Cllocationmanager locationservicesenabled];
CGFloat Verson = [[Uidevice currentdevice].systemversion Doublevalue];//float
if (isenable) {
if (!_loactionmanager) {
_loactionmanager = [[Cllocationmanager alloc] init];
[_loactionmanager setdelegate:self];
_loactionmanager.desiredaccuracy = Kcllocationaccuracybest;
_loactionmanager.distancefilter = 20.0;//is positioned every 10 meters
if (Verson > 8.0f) {
[_loactionmanager requestalwaysauthorization];
}
[_loactionmanager startupdatinglocation];
}
}
else {
Alert (@ "Warm tip", @ "Current device positioning function is not turned on!", we recommend that you turn on location services in [Set]->[privacy]->[Location Services] on your mobile system and allow "XXXX community" to use location services ");
Return
}
}
3. To add two key values in a pist file
Nslocationalwaysusagedescription nslocationwheninuseusagedescription This two key value added in this directory application requires IPhone Environment
4. Set up proxy methods
#pragma the Mark Proxy method
-(void) Locationmanager: (Cllocationmanager *) Manager
Didupdatelocations: (Nsarray *) Locations
{
Cllocation *currentlocation = [locations Lastobject];
Mjlog (@ "currentlocation = =%@", currentlocation);
Create location
Clgeocoder *revgeo = [[Clgeocoder alloc] init];
[Revgeo reversegeocodelocation:currentlocation completionhandler:^ (Nsarray *placemarks, NSError *error) {
Geo-editing
if (!error && [placemarks count] > 0) {
Nsdictionary *dict = [[Placemarks objectatindex:0] addressdictionary];
_currentposition = [dict objectforkey:@ "City"];
Mjlog (@ "City Address:%@", _currentposition); }
else {
Alert (@ "Warm tip", @ "Get location failed");
Mjlog (@ "error:%@", error); }
}];
}
-(void) Locationmanager: (Cllocationmanager *) Manager
Didfailwitherror: (Nserror *) error
{
Mjlog (@ "error:%@", [Error localizeddescription]);
}
IOS 8 Targeting