Get information about the user's current location under iOS

Source: Internet
Author: User

#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

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.