2012-01-27 16 views
5

Tôi có câu hỏi liên quan đến mã hóa địa lý đảo ngược.Mục tiêu c cách nhận dấu vị trí của các toạ độ đã cho

Trong ứng dụng của mình, tôi có một số toạ độ (không phải tọa độ hiện tại của tôi) và tôi muốn chuyển đổi chúng thành dấu vị trí. Tôi đã đào rất nhiều trang web và mã nhưng tất cả đều là mã hóa địa lý ngược của vị trí hiện tại ...

Có cách nào để nhận dấu vị trí của toạ độ được chỉ định (không phải là vị trí hiện tại) không?

Và nếu có, vui lòng giúp tôi với một số mã hoặc tham chiếu.

+0

Ý 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

+0

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

+2

'CLLocation * loc = [[Phân bổ CLLocation] initWithLatitude: kinh độ vĩ độ: kinh độ];' – vakio

Trả lời

2

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); 

    } 
+0

chỉ cần lưu ý: trong iOS 5.0, nó không được dùng nữa của lớp 'GLGeocoder': http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLGeocoder_class/Reference/Reference.html#//apple_ref/occ/cl/CLGeocoder – Krizz

+0

Tôi khuyên bạn nên sử dụng phương pháp google api. Nó rất dễ dàng và đáng tin cậy hơn. – Gypsa

+0

Cảm ơn Gypsa Tôi sẽ cố gắng tiếp cận đầu tiên nhưng như tôi biết MKReverseGeoCoder được depricated trong iOS 5. Cảm ơn trước – Garnik

Các vấn đề liên quan