-
Add Corelocation.framework Frame
-
Import #import <CoreLocation/CoreLocation.h>
-
To query the latitude and longitude method by address:
-
CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeaddressstring:@ "Xiangyang, Hubei" completionhandler:^ (Nsarray* placemarks, nserror* error) { if (!error) { for (Clplacemark* aplacemark in placemarks) { nslog (@ "place--%@", [aplacemark locality]); nslog (@ "Lat--%f--lon--%f", Aplacemark.location.coordinate.latitude,aplacemark.location.coordinate.longitude); } } else{ nslog (@ "error--%@", [error localizeddescription]); } }];
5. Querying address by Latitude method:
CLLocation * newLocation = [[CLLocation alloc]initWithLatitude:30.590865 Longitude:104.061792]; nslog (@ "-------based on latitude and longitude to reverse the location--%f--%f", Sendercoordinate.latitude,sendercoordinate.longitude); clgeocoder *clgeocoder = [[clgeocoder alloc] init]; [ clgeocoder reversegeocodelocation:newlocation completionhandler: ^ (NSArray *placemarks, Nserror *error) { nslog (@ "--array--%d---error--%@", (int) placemarks.count,error); if (placemarks.count > 0) { clplacemark *placemark = [placemarks objectatindex:0]; nsstring *city = Placemark.administrativearea; nslog (@ " Located at:%@ ", city); nslog (@"%@ ", placemark.addressdictionary[@ "Name"]); } }];
iOS development uses Clgeocoder to achieve latitude and longitude and address mutual search