2012-04-27 6 views
0

私は2つの場所の間にルートを描こうとしています。そのために私は2つを持っていますCLLocation(startPoint ,endPoint)。この2つの場所のMKReverseGeocoderの後、私はこのように置いた。CLLocation CordinateでReverseGeocoderを実行した後、Google Map Webサービスに正確な場所を教えてください。

- (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を送っているため、この2つの場所の間でルートポイントを取得します。

- (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を渡したいました。だから私はstartLocationendLocationMKReverseGeocoder代理人の返品(cplace1とcplace2)から割り当てる必要がありますか?

答えて

0

CLLocationオブジェクトのように開始位置と終了位置が既にあるようですので、Googleに渡す場合はcoordinate(これはCLLocationCoordinate2D)の値を使用してください。

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キーを設定せずにテストすることができませんでした。 –

関連する問題