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