2 つの場所の間のルートを描画しようとしていますCLLocation
。そのために、startPoin、endPoind の 2 つのインスタンスがあります。この 2 つの場所を 2 つの対応する場所の住所に変換したいと考えています。その後、Google マップ Web サービスからすべてのルート ポイントを取得したいと考えています。次のコードも同様です。
- (void)viewDidLoad{
[super viewDidLoad];
locations =[[NSMutableArray alloc]initWithCapacity:2];//For location Name
[self.mapView_MP setMapType:MKMapTypeStandard];
[self.mapView_MP setZoomEnabled:YES];
[self.mapView_MP setScrollEnabled:YES];
[self update:startPoint]; //MKReverseGeocoder start point
[self update:endPoint]; //MKReverseGeocoder end point
[self updateRoute];
}
- (void)update:(CLLocation*)loc{
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:loc.coordinate];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
NSMutableDictionary *cplace=[[NSMutableDictionary alloc]initWithDictionary:[placemark addressDictionary]];
// NSLog(@"The geocoder has returned: %@", [cplace objectForKey:@"FormattedAddressLines"] );
// NSLog(@"The geocoder has returned: %@", [cplace objectForKey:@"Street"] );
[locations addObject:[cplace objectForKey:@"SubAdministrativeArea"]];
NSLog(@"The geocoder has returned: %@", locations );
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSLog(@"reverseGeocoder:%@ didFailWithError:%@", geocoder, error);
}
- (void)updateRoute {
self.responseData=[NSMutableData data];
NSLog(@" string Formate.................................===%@",locations);
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&mode=driving&sensor=false", [locations objectAtIndex:0],[locations objectAtIndex:1]]]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
viewDidLoad では、順番にメソッドを呼び出しています
[self update:startPoint]; //MKReverseGeocoder start point
[self update:endPoint]; //MKReverseGeocoder end point
[self updateRoute];
残念ながら [self updateRoute]; MKReverseGeocoder
デリゲート メソッドとの最初の比較を実行しています。このメソッドの側で位置配列がnullであるためです。EXEBADACCESS を取得します。どうすればこの値を克服できますか。MKReverseGeocoder
デリゲート メソッド内で、場所の名前を取得しました。Delegate メソッドは他のスレッドを実行しています。