0

2つの場所の間にルートを描画しようとしています。そのために私は2つ持っていCLLocation (startPoint ,endPoint)ます。MKReverseGeocoderこの2つの場所の後、私はこのように出ました。

- (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";
}

ここで、この2つの場所の間のルートポイントを取得したいと思います。そのために、このように送信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];    
      }  

問題は、私が合格startLocationしたいということでしendLocationNSURLRequest。では、どの値を割り当てる必要がstartLocationありendLocationMKReverseGeocoderデリゲートreturn(cplace1およびcplace2)からですか?

4

1 に答える 1

0

CLLocationすでに開始位置と終了位置がオブジェクトとして存在しているように見えるので、それらの値coordinateCLLocationCoordinate2D)を使用してGoogleに渡します。

startPointとendPointのCLLocationCoordinate2D両方に、タイプのalatitudeとが含まれています。は実際にはdoubleなので、次のようにフォーマットされた文字列に入れることができます。longitudeCLLocationDegreesCLLocationDegrees%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]];
于 2012-04-27T10:11:46.317 に答える