以當前手機為例:
獲取當前手機地址,再從經(jīng)緯度轉換成詳細地址(包括:國家名-國家代碼,省,市,街道名,郵政代代碼等)。
1:獲取當前手機經(jīng)緯度
reverse geoder class
1:- (void)startedreversegeoderwithlatitude:(double)latitude longitude:(double)longitude{ cllocationcoordinate2d coordinate2d; coordinate2d.longitude = longitude; coordinate2d.latitude = latitude; // if (self.locationinfo == nil) { self.locationinfo = [[[location alloc] init] autorelease]; } self.locationinfo.latitude = latitude; self.locationinfo.longitude = longitude; // mkreversegeocoder *geocoder = [[mkreversegeocoder alloc] initwithcoordinate:coordinate2d]; geocoder.delegate = self; [geocoder start];}#pragma mark -#pragma mark mkreversegeocoderdelegate methods- (void)reversegeocoder:(mkreversegeocoder *)geocoder didfindplacemark:(mkplacemark *)placemark { nslog(@reverse finished...); nslog(@country:%@,placemark.country); nslog(@countrycode:%@,placemark.countrycode); nslog(@locality:%@,placemark.locality); nslog(@sublocality:%@,placemark.sublocality); nslog(@postalcode:%@,placemark.postalcode); nslog(@subthoroughfare:%@,placemark.subthoroughfare); nslog(@thoroughfare:%@,placemark.thoroughfare); nslog(@administrativearea:%@,placemark.administrativearea); self.locationinfo.locationname = [nsstring stringwithformat:@%@ @ @, placemark.country, placemark.administrativearea, placemark.locality, placemark.sublocality, placemark.thoroughfare]; nslog(@administrativearea:%@,self.locationinfo.locationname); [self.target performselector:self.callback withobject:@0]; geocoder = nil;}- (void)reversegeocoder:(mkreversegeocoder *)geocoder didfailwitherror:(nserror *)error { nslog(@error %@ , error); [self.target performselector:self.callback withobject:@1];}
2:獲取當前手機經(jīng)緯度的, 詳細地址。
current location class
-(void) startupdatinglocation{ // start the location manager. [[selflocationmanager] startupdatinglocation]; }#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;}/** conditionally enable the add button: if the location manager is generating updates, then enable the button; if the location manager is failing, then disable the button. */- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { [self.target performselector:self.callback withobject:@0];}- (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { [self.target performselector:self.callback withobject:@1];}
更多信息請查看IT技術專欄