Take detailed address according to latitude and longitude coordinates (including country, province, city, street, number)

Source: Internet
Author: User
Tags error handling

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"

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.