2012-04-27 1 views
0

두 위치 사이에 경로를 그리려합니다. 그 때문에 나는 두있다 CLLocation(startPoint ,endPoint). 이 2 개의 위치의 MKReverseGeocoder 이후 나는 이것을 꺼내졌다.CLLocation Cordinate에서 ReverseGeocoder를 수행 한 후 정확한 위치를 위해 Google지도 웹 서비스에 무엇을 제공해야합니까?

- (void)findAddress{  
    geoCoder1 = [[MKReverseGeocoder alloc] initWithCoordinate:startPoint.coordinate]; 
    geoCoder1.delegate = self; 
    [geoCoder1 start];   
    geoCoder2 = [[MKReverseGeocoder alloc] initWithCoordinate:endPoint.coordinate];  
    geoCoder2.delegate = self; 
    [geoCoder2 start];  
} 
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
    if(geocoder==geoCoder1){ 
      NSMutableDictionary *cplace1=[[[NSMutableDictionary alloc]initWithDictionary:[placemark addressDictionary]] autorelease]; 
      NSLog(@"The MKReverseGeocoder Start Point Address %@", cplace1); 

     }else{ 
      NSMutableDictionary *cplace2=[[[NSMutableDictionary alloc]initWithDictionary:[placemark addressDictionary]] autorelease];    
      NSLog(@"The MKReverseGeocoder End Point Address %@", cplace2); 
     } 
} 

아웃 넣어 : -

The MKReverseGeocoder Start Point Address { 
    City = Bangalore; 
    Country = India; 
    CountryCode = IN; 
    FormattedAddressLines =  (
     "Grant Rd, Sampangi Rama Nagar", 
     "Bangalore, Karnataka", 
     India 
    ); 
    State = Karnataka; 
    Street = "Grant Rd"; 
    SubAdministrativeArea = "Bengaluru Rural"; 
    SubLocality = "Sampangi Rama Nagar"; 
    Thoroughfare = "Grant Rd"; 
} 

The MKReverseGeocoder End Point Address { 
    Country = India; 
    CountryCode = IN; 
    FormattedAddressLines =  (
     "NH47 Bi - Rd", 
     "Ernakulam, Kerala", 
     India 
    ); 
    State = Kerala; 
    Street = "NH47 Bi - Rd"; 
    SubAdministrativeArea = Ernakulam; 
    Thoroughfare = "NH47 Bi - Rd"; 
} 

지금 내가 이런 NSURLRequest를 전송하는 경우,이 두 위치 사이의 경로 포인트를 검색합니다.

- (void)updateRoute { 
     NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat: 
@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&mode=%@&sensor=false", startLocation,endLocation,routeMode] ]]; 

     [[NSURLConnection alloc] initWithRequest:request delegate:self];  
     } 

문제

내가 NSURLRequeststartLocationendLocation을 전달하려는이었다. 그래서 어떤 값을 startLocationendLocation에서 MKReverseGeocoder 대리인 반환 (cplace1 및 cplace2) 할당해야합니까?

답변

0

이미 시작 및 끝 위치가 CLLocation 개 인 것처럼 보입니다. 따라서 coordinate (CLLocationCoordinate2D)의 값을 사용하여 Google에 전달할 수 있습니다.

startPoint 및 endPoint의 CLLocationCoordinate2D은 모두 CLLocationDegrees 유형의 latitudelongitude을 포함합니다. 정확히 %f

NSString *googleURL = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%f,%f&destination=%f,%f&mode=%@&sensor=false", 
    startPoint.coordinate.latitude,startPoint.coordinate.longitude, 
    endPoint.coordinate.latitude,endPoint.coordinate.longitude, 
    routeMode]; 

NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:googleURL]]; 
+0

으로 포맷 된 문자열로 넣을 수 CLLocationDegrees 정말 두 배입니다. 하지만 누락 된 "좌표"즉 startPoint.coordinate.latitude, startPoint.coordinate.longitude, endPoint.coordinate.latitude, endPoint.coordinate.latitude – Musthafa

+0

위치 좌표 용 MKReverseGeocoder – Musthafa

+0

아, 맞아요. 나는'CLLocationCoordinate2D'와'CLLocation'을 섞었다. 이미 정확한 위치를 가지고 있으므로 역 지오 코더가 필요하지 않습니다. 다시 돌아 가면 API 키를 설정하지 않고 테스트 할 수 없습니다. –