I'm stuck in a weird problem. I am currently working on mapkit on iPhone. I need to show two routes in my map, for which there is a source city and two different destination. For a route between two cities my code was fine. for that purpose in one place in my code i was doing like this….
- (void)loadWithStartPoint:(NSString *)startPoint endPoint:(NSString *)endPoint options:(UICGDirectionsOptions *)options {
[googleMapsAPI stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"loadDirections('%@', '%@', %@)", startPoint, endPoint, [options JSONRepresentation]]];
}
In the above code stringByEvaluatingJavaScriptFromString was passing javascript to my delegate method due to which route was drawn. Now, i have to draw two different routes, for that purpose i have changed above code like this..
- (void)loadWithStartPoint:(NSString *)startPoint endPoint:(NSMutableArray *)endPoints options:(UICGDirectionsOptions *)options {
for (int idx = 0; idx < [endPoints count];idx ++)
{
NSString* msg = [NSString stringWithFormat:@"loadDirections('%@', '%@', %@)", startPoint, [endPoints objectAtIndex:idx], [options JSONRepresentation]];
mstr = [msg retain];
if (idx == 0)
{
[googleMapsAPI stringByEvaluatingJavaScriptFromString:msg];
}
else {
[NSThread detachNewThreadSelector:@selector(loadroute:) toTarget:self withObject:mstr];
}
}
}
i have the following to create and implement NSThread.
-(void)loadroute :(NSString *)message
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(loadComplete:) withObject:message waitUntilDone:YES];
[pool release];
}
-(void)loadComplete:(NSString *)message
{
[googleMapsAPI stringByEvaluatingJavaScriptFromString:message];
}
here, i have created another thread due to which i would be able to pass strings to stringByEvaluatingJavaScriptFromString separately. But only the last string is passed to the delegate method.What i'm missing? please help me out. i'm stuck in this weird problem since last week. Any help would be appreciated. Thnx in advance.