#import <MapKit/MKMapView.h> @interface Viewcontroller () {Cllocationmanager *_currentloaction; Clgeocoder *_geocoder; Clplacemark *_placemark;} -(void) viewdidload{[Super viewdidload];//do no additional setup after loading the view, typically from a nib. _geocoder = [[Clgeocoder alloc] init]; _currentloaction = [[Cllocationmanager alloc] init]; _currentloaction.delegate = self; [_currentloaction startupdatinglocation]; } #pragma mark-location-(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error {NSLog ( @ "locerror:%@", error);} -(void) Locationmanager: (Cllocationmanager *) Manager didupdatetolocation: (cllocation *) newlocation fromlocation: ( Cllocation *) oldlocation {cllocationcoordinate2d locat = [NewLocation coordinate]; Double lattitude = locat.latitude; Double longitude = locat.longitude; Clgeocodecompletionhandler handler = ^ (Nsarray *placemark, Nserror *error) {for (Clplacemark *mark in PLAcemark) {nsmutabledictionary *area_dic = [Mark Addressdictionary]; [Area_dic setvalue:[nsstring stringwithformat:@ "%f", Lattitude] forkeypath:@ "Lattitude"]; [Area_dic setvalue:[nsstring stringwithformat:@ "%f", longitude] forkeypath:@ "longitude"]; NSLog (@ "Area_dic is%@", area_dic); Nsarray *array = [area_dic objectforkey:@ "Formattedaddresslines"]; NSString *address = [area_dic objectforkey:@ "Formattedaddresslines"]; NSLog (@ "Array is%@", array); address = [array objectatindex:0]; NSLog (@ "address is%@", address); address = [Area_dic objectforkey:@ "City"]; NSLog (@ "City is%@", address); } }; [_geocoder reversegeocodelocation:newlocation Completionhandler:handler];}
Get information about the user's current location under iOS