iOS geo-geocoding--corelocation

Source: Internet
Author: User

Ios--corelocation Geo-geocoding

Operation Steps

    • 1. Import the framework
Corelocation/corelocation.h
    • 2. Setting properties
@property (nonatomic, strong) Clgeocoder *geocoder;
    • 3. Method implementation

3.1 Lazy Load Create Geocoder property

-(Clgeocoder *) geocoder{    if (!_geocoder) {        self.geocoder = [[Clgeocoder alloc] init];    }    return _geocoder;}

3.2 geocoding

Geo-(void) dili{//geocoding method NSString *straddress = @ "Beijing"; [Self.geocoder geocodeaddressstring:straddress completionhandler:^ (Nsarray *placemarks, NSError *error)        {if (error) {//has error NSLog (@ "Cannot find this address");                        } else {///code succeeds//takes out the front address clplacemark *pm = [Placemarks firstobject];            Remove the latitude and longitude of cgfloat latitude = pm.location.coordinate.latitude;                                          CGFloat longitude = pm.location.coordinate.longitude;                        NSLog (@ "A total of%d addresses found", placemarks.count);                                For (Clplacemark *pm in Placemarks) {NSLog (@ "-----address starts----");                                NSLog (@ "%f%f%@", Pm.location.coordinate.latitude, Pm.location.coordinate.longitude, pm.name); [Pm.addressdictionary enumeratekeysandobjectsusingblock:^ (ID key, id obj, BOOL *stop)              {NSLog (@ "%@%@", key, obj);  }];            NSLog (@ "-----address end----"); }        }    }];}

3.3 Anti-geocoding

Anti-geo-(void) fandili{//anti-geocoding//1. Position cllocationdegrees latitude = 114.0;    Cllocationdegrees longitude = 45.0;        Cllocation *loc = [[Cllocation alloc] Initwithlatitude:latitude longitude:longitude];        2. Anti-geocoding [Self.geocoder reversegeocodelocation:loc completionhandler:^ (Nsarray *placemarks, NSError *error) {        if (error) {//There is an error (address disorderly input) NSLog (@ "Cannot find this address");            } else {///code succeeds//takes out the front address clplacemark *pm = [Placemarks firstobject];            NSLog (@ "%@", pm.name);                        Set the specific address NSLog (@ "A total of%ld addresses found", (long) placemarks.count);                                For (Clplacemark *pm in Placemarks) {NSLog (@ "-----address starts----");                                NSLog (@ "%f%f%@", Pm.location.coordinate.latitude, Pm.location.coordinate.longitude, pm.name); [Pm.addressdictionary enumeratekeysandobjectsusingblock:^ (ID key, id obj, BOOL *stop) {NSLog (@ "%@%@ ", key, obj);                                }];            NSLog (@ "-----address end----"); }        }    }];}

3.4 Calling methods

-(void) viewdidload {    [super viewdidload];            [Self Dili];    [Self Fandili];}

iOS geo-geocoding--corelocation

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.