// Create location service object
Locationmanager = [[cllocationmanager alloc] init];
Locationmanager. Desiredaccuracy = kcllocationaccuracybest;
// set up a location agent
Locationmanager. Delegate = self;
// If it's really iOS8.0 , we need to add the following:
//1. Call method --requestwheninuseauthorization or requestalwaysauthorization
//2.
if ([uidevice currentdevice]. Systemversion. Floatvalue >= 8.0) {
[locationmanager requestwheninuseauthorization];
}
// start positioning
[locationmanager startupdatinglocation];
}
-(void) didreceivememorywarning {
[super didreceivememorywarning];
//Dispose of any resources, can be recreated.
}
#pragma mark-cllocationmanagerdelegate
-(void) Locationmanager: (cllocationmanager *) Manager didupdatetolocation: (cllocation *) NewLocation fromlocation: (cllocation *) oldlocation
{
NSLog (@ " positioning success ");
// stop positioning
[locationmanager stopupdatinglocation];
cllocationcoordinate2d coordinate = newlocation. coordinate;
NSLog (@ " location: Latitude:%.2f---- Longitude:%.2f", coordinate. latitude, coordinate. longitude);
}
-(void) Locationmanager: (cllocationmanager *) Manager
Didupdatelocations: (nsarray *) Locations
{
NSLog(@ " New method Positioning success ");
// stop positioning
[locationmanager stopupdatinglocation];
cllocation *location = [Locations lastobject];
cllocationcoordinate2d coordinate = location. coordinate;
NSLog (@ " location: Latitude:%.2f---- Longitude:%.2f", coordinate. latitude, coordinate. longitude);
}
Map location Information