First the header file should inherit cllocationmanagerdelegate.
And: #import <CoreLocation/CoreLocation.h>
The following code is written in the response event:
Cllocationmanager *_locmanager = [[Cllocationmanager alloc] init];
[_locmanager setdelegate:self];
[_locmanager Setdesiredaccuracy:kcllocationaccuracybest];
[_locmanager startupdatinglocation];
Overload
#pragma mark-
#pragma Mark Location Manager
-(void) Locationmanager: (Cllocationmanager *) Manager
Didupdatetolocation: (cllocation *) newlocation
Fromlocation: (cllocation *) oldlocation
{
Cllocationcoordinate2d loc = [newlocation coordinate];
NSString *lat =[nsstring stringwithformat:@ "%f", Loc.latitude];//get latitude
NSString *lon =[nsstring stringwithformat:@ "%f", Loc.longitude];//get longitude
NSLog (@ "%@%@", Lat,lon);
}
How to get the current latitude and longitude of mobile phone