Bạn có thể đạt được điều này theo hai cách: -
cách thứ nhất: - thập các thông tin sử dụng google api
-(void)findAddresstoCorrespondinglocation
{
NSString *str = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",myCoordInfo.latitude,myCoordInfo.longitude];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setRequestMethod:@"GET"];
[request setDelegate:self];
[request setDidFinishSelector: @selector(mapAddressResponse:)];
[request setDidFailSelector: @selector(mapAddressResponseFailed:)];
[networkQueue addOperation: request];
[networkQueue go];
}
để đáp ứng bạn sẽ nhận được tất cả các thông tin về vị trí tọa độ mà bạn chỉ định.
Thứ hai cách tiếp cận: -
Thực hiện đảo ngược mã hóa địa lý
a) thêm mapkit
khuôn khổ
b) Hãy thể hiện của MKReverseGeocoder
trong file .h
MKReverseGeocoder *reverseGeocoder;
c)... trong tệp .m
self.reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:cordInfo];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
Thực hiện hai phương pháp đại biểu của MKReverseGeoCoder
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@"MKReverseGeocoder has failed.");
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
MKPlacemark * myPlacemark = placemark;
NSString *city = myPlacemark.thoroughfare;
NSString *subThrough=myPlacemark.subThoroughfare;
NSString *locality=myPlacemark.locality;
NSString *subLocality=myPlacemark.subLocality;
NSString *adminisArea=myPlacemark.administrativeArea;
NSString *subAdminArea=myPlacemark.subAdministrativeArea;
NSString *postalCode=myPlacemark.postalCode;
NSString *country=myPlacemark.country;
NSString *countryCode=myPlacemark.countryCode;
NSLog(@"city%@",city);
NSLog(@"subThrough%@",subThrough);
NSLog(@"locality%@",locality);
NSLog(@"subLocality%@",subLocality);
NSLog(@"adminisArea%@",adminisArea);
NSLog(@"subAdminArea%@",subAdminArea);
NSLog(@"postalCode%@",postalCode);
NSLog(@"country%@",country);
NSLog(@"countryCode%@",countryCode);
}
Ý anh là gì? Bạn sẽ phải làm điều tương tự cho dù vị trí là của bạn hay không. Dưới đây là một số tham khảo nếu bạn đang phát triển cho iOS 5: http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLGeocoder_class – vakio
Bạn không thể chỉ định vị trí cho CLLocation.coordinat.longitude hoặc latitude. và phương thức reverseGeoCoding chỉ chấp nhận CLLocation không CLLocationCoordinate2D – Garnik
'CLLocation * loc = [[Phân bổ CLLocation] initWithLatitude: kinh độ vĩ độ: kinh độ];' – vakio