IOS Targeting geo-encoding

Source: Internet
Author: User

- (void) viewdidload {[Self startlocation];}//Start Positioning-(void) startlocation{Self.locationmanager=[[Cllocationmanager alloc] init]; Self.locationmanager.Delegate=Self ;    [Self.locationmanager requestwheninuseauthorization]; if([[[[Uidevice currentdevice]systemversion]doublevalue]>=8.0) {[Self.locationmanager requestwheninuseauthorization];            [Self.locationmanager requestalwaysauthorization];        } [Self.locationmanager startupdatinglocation]; if([Cllocationmanager locationservicesenabled]) {self.locationManager.desiredAccuracy=kcllocationaccuracynearesttenmeters; Self.locationManager.distanceFilter=Kcldistancefilternone; }Else{NSLog (@"Open Fail"); }    }#pragmaMark-corelocation Agent#pragmaMark tracks the location agent method, which is executed each time the position changes (as long as it is positioned to the appropriate location)-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{cllocation*location=[Locations Lastobject]; cllocationcoordinate2d coordinate=location.coordinate; NSLog (@"Longitude:%f, Latitude:%f", Coordinate.longitude,coordinate.latitude); Self.longitude=Coordinate.longitude; Self.latitude=Coordinate.latitude; //If you don't need real-time positioning, use it even if you turn off location services[Self.locationmanager stopupdatinglocation]; [Self Weizhi];}-(void) weizhi{Self.geocoder=[[Clgeocoder alloc]init]; Cllocation*rr=[[Cllocation alloc]initwithlatitude:self.latitude longitude:self.longitude]; [Self.geocoder reversegeocodelocation:rr Completionhandler:^ (Nsarray *placemarks, Nserror *error) {Clplacemark*mark=[placemarks Objectatindex:0]; UILabel*currentlocation=[[uilabel Alloc]initwithframe:cgrectmake ( -, the, -, -)]; Currentlocation.text=[nsstring stringWithFormat:@"%@", mark.sublocality];    [Self.locationview addsubview:currentlocation]; }];}-(void) Locationmanager: (Cllocationmanager *) Manager didchangeauthorizationstatus: (clauthorizationstatus) status{Switch(status) { Casekclauthorizationstatusnotdetermined:if([Self.locationmanager respondstoselector: @selector (requestalwaysauthorization)]) {[Self.locatio         Nmanager Requestwheninuseauthorization]; }          Break; default:          Break; }}//This method is called when the location error occurs. - (void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (Nserror*) error{NSLog (@"error-%@", error);}

Locates the current location. There are many properties for Clplacemark, not only the current location, but also other information, follow-up research ....

IOS Targeting geo-encoding

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.