Get the current phone address, and then convert from latitude and longitude to detailed address (including: Country name-Country code, province, city, street name, postal code, etc.).
1: Get current phone latitude and longitude
@implementation currentlocation @synthesize Locationmanager;
@synthesize Target,callback; #pragma mark-#pragma mark public-(void) startupdatinglocation{[[Self Locationmanager] startupdatinglocation];} #pra
GMA Mark-#pragma mark Memory management-(void) dealloc{[Super Dealloc];
[Locationmanager release];
#pragma mark-#pragma mark location Manager/* Return A location Manager-create one if necessary.
*/-(Cllocationmanager *) Locationmanager {if (Locationmanager! = nil) {return locationmanager;}
Locationmanager = [[Cllocationmanager alloc] init];
[Locationmanager Setdesiredaccuracy:kcllocationaccuracynearesttenmeters];
[Locationmanager setdelegate:self];
return locationmanager; } #pragma mark-#pragma mark cllocationmanagerdelegate methods/* Conditionally enable the ADD button:if the location
Manager is generating updates and then enable the button;
If The location manager is failing and then disable the button. */-(void) Locationmanager: (Cllocationmanager *) Manager didupdatetolocation: (cllocation *) newlocation fromlocation: (cllocation *) OldLoc ation {NSLog (@) Gets the latitude and longitude.
");
} -(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error {NSLog (@ "Get failed.
");
} @end
2: Get the detailed address of the current phone's latitude and longitude
@implementation Addressreversegeoder #pragma mark--#pragma mark public//start getting detailed address information based on latitude and longitude-(void) startedreversegeoderw
Ithlatitude: (double) latitude Longitude: (double) longitude{cllocationcoordinate2d coordinate2d;
Coordinate2d.longitude = longitude;
Coordinate2d.latitude = latitude;
Mkreversegeocoder *geocoder = [[Mkreversegeocoder alloc] initwithcoordinate:coordinate2d];
Geocoder.delegate = self;
[GeoCoder start]; } #pragma mark-#pragma mark mkreversegeocoderdelegate methods//Get address information-(void) Reversegeocoder: (Mkreversegeocoder *) GE
Ocoder Didfindplacemark: (Mkplacemark *) placemark {nsstring *address = [NSString stringwithformat:@ "%@%@%@%@%@%@", Placemark.country, Placemark.administrativearea, Placemark.locality, Placemark.
Sublocality, Placemark.thoroughfare, Placemark.subthoroughfare];
NSLog (@ "latitude and longitude of the corresponding details:%@", address);
Geocoder = nil; }//error handling-(void) Reversegeocoder: (Mkreversegeocoder *) Geocoder didFailwitherror: (Nserror *) error {NSLog (@ "Error%@", error)} #pragma mark-#pragma mark Memory management-(void) DEA
Lloc {[Super Dealloc];} @end
@property (nonatomic, readonly) nsdictionary *addressdictionary; Address dictionary
@property (nonatomic, readonly) NSString *thoroughfare; Street name--"Ke Yun Road"
@property (nonatomic, readonly) NSString *subthoroughfare; Number--"No. 18th"
@property (nonatomic, readonly) NSString *locality; City-"Guangzhou"
@property (nonatomic, readonly) NSString *sublocality; Districts and counties-"Tianhe District"
@property (nonatomic, readonly) NSString *administrativearea; Identity--"Guangdong province"
@property (nonatomic, readonly) NSString *subadministrativearea; I don't get it, I don't know what it is.
@property (nonatomic, readonly) NSString *postalcode; Zip code--I don't know what the reason is, I didn't get it here.
@property (nonatomic, readonly) NSString *country; Country-"China"
@property (nonatomic, readonly) NSString *countrycode; Country code--"CN"