Я реализовал API Карт Google для iOS. Я успешно загрузил карту и сбросил на нее два булавки. Я также реализовал API Google Maps Directions, и я получил ответ Json. Я не знаю, как его декодировать и показывать маршруты на карте.Отображение направлений от JSON Информация
Вот код:
В direction.h
-(void)retrieveDirectionsFromOrigin:(CLLocationCoordinate2D)origin toDestination:(CLLocationCoordinate2D)destination
{
NSString *directionsURL=[NSString stringWithFormat:@"http://maps.google.com/maps/api/directions/json? origin=%f,%f&destination=%f,%f&sensor=false",origin.latitude,origin.longitude,destination.longitude,destination.longitude];
_directionsURL=[NSURL URLWithString:directionsURL];
[self retrieveDirections:nil withDelegate:self];
}
-(void)retrieveDirections:(SEL)selector withDelegate:(id)delegate{
dispatch_async(dispatch_get_main_queue(), ^{
NSData *data = [NSData dataWithContentsOfURL:_directionsURL];
[self fetchedData:data withDelegate:delegate];
});
}
-(void)fetchedData:(NSData *)data withDelegate:(id)delegate{
NSError* error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"Directions %@",json);
}
В MapViewController.h
-(void)viewDidLoad
{
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
GMSMarker *marker2 = [[GMSMarker alloc]init];
marker.position = CLLocationCoordinate2DMake(21.422492, 39.826169);
marker2.position = CLLocationCoordinate2DMake(21.413333, 39.893333);
marker.map = mapView;
marker2.map = mapView;
directions=[[Directions alloc]init];
[directions retrieveDirectionsFromOrigin:marker.position toDestination:marker2.position];
[mapViewView setNeedsDisplay];
[mapView setNeedsDisplay];
}
Пожалуйста, дайте мне знать, что делать дальше.