IOS Reverse-track place names based on latitude and longitude

Source: Internet
Author: User

In iOS
Positioning your current location, know the latitude and longitude is very simple, and then some time to know the place name, Apple also has a ready-made API directly call can (the following method is iOS5.0 above, and now basically ignore the iOS5.0 below the device)

#pragma mark-#pragma mark Cllocationmanagerdelegate-(void) Locationmanager: (Cllocationmanager *) Manager Didupdatetolocation: (cllocation *) newlocation fromlocation: (cllocation *) oldlocation {Clgeocoder *GEOCODER=[[CLGEOC    Oder alloc] init];                                       [Geocoder reversegeocodelocation:newlocation completionhandler:^ (Nsarray *placemarks,        Nserror *error) {Clplacemark *placemark=[placemarks objectatindex:0]; NSLog (@ "name:%@\n country:%@\n postalcode:%@\n isocountrycode:%@\n ocean:%@\n inlandwater:%@\n locality:%@\n              sublocality:%@ \ administrativearea:%@\n subadministrativearea:%@\n thoroughfare:%@\n subThoroughfare:%@\n ", Placemark.name, Placemark.country, Placemark.postalcode, Placemark. Isocountrycode, Placemark.ocean, Placemark.inlandwater, placemark.administrative       Area, Placemark.subadministrativearea,       Placemark.locality, Placemark.sublocality, Placemark.thoroughfare, Placem     Ark.subthoroughfare);    }];if (WasFound) return;    WasFound = YES; Cllocationcoordinate2d loc = [NewLocation coordinate];strlatitude = [NSString stringWithFormat: @ "%f", Loc.latitude]; Strlongitude = [NSString stringWithFormat: @ "%f", Loc.longitude]; NSLog (@ "strlatitude==%@,strlongitude==%@", strlatitude,strlongitude); }

Log is:

Name: Civic Plaza Country: China PostalCode: (NULL) ISOCOUNTRYCODE:CN ocean: (NULL) Inlandwater: (null) locality: Guangdong Province sublocality: ( NULL)  Administrativearea: Shenzhen subadministrativearea: Futian District thoroughfare: Civic Square Subthoroughfare: (null)

The second method is that we already know a latitude and longitude and then reverse the name of the place:

Write a method yourself:

-(void) change{//22.540681,=114.061324 cllocationcoordinate2d coordinate;    Coordinate.latitude = 22.540681;    Coordinate.longitude = 114.061324;    Cllocation *newlocation=[[cllocation Alloc]initwithlatitude:coordinate.latitude Longitude:coordinate.longitude];    Clgeocoder *geocoder=[[clgeocoder alloc] init];                                       [Geocoder reversegeocodelocation:newlocation completionhandler:^ (Nsarray *placemarks,         Nserror *error) {Clplacemark *placemark=[placemarks objectatindex:0]; NSLog (@ "My my:%@\n country:%@\n postalcode:%@\n isocountrycode:%@\n ocean:%@\n inlandwater:%@\n locality:%@\n               sublocality:%@ \ administrativearea:%@\n subadministrativearea:%@\n thoroughfare:%@\n subThoroughfare:%@\n ", Placemark.name, Placemark.country, Placemark.postalcode, Placemark. Isocountrycode, Placemark.ocean, placemark.inlandwater, plAcemark.administrativearea, Placemark.subadministrativearea, Placemark.locality,     Placemark.sublocality, Placemark.thoroughfare, Placemark.subthoroughfare); }];}

The result of the NSLog is the same as above.

IOS Reverse-track place names based on latitude and longitude

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.