I am trying draw route between two location.For that i have two instance of CLLocation
startPoin,endPoind. I want to convert this two location two corresponding Location Address.After that i want to fetch all route points from Google map webservice. So did the following code.
- (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];
}
鉴于DidLoad i正在按顺序排列方法。
[self update:startPoint]; //MKReverseGeocoder start point
[self update:endPoint]; //MKReverseGeocoder end point
[self updateRoute];
but unfortunately [self updateRoute]; is executing first compare to MKReverseGeocoder
delegate method. there for the location array is null in side this method. Getting EXEBADACCESS. how can i over come this value.
Inside MKReverseGeocoder
delegate method i got location name. the Delegate methods is executing any other thread.