iOS 용 Google Maps API를 구현했습니다. 나는 성공적으로지도를로드하고 그것에 두 개의 핀을 떨어 뜨렸다. 또한 Google Maps Directions API를 구현했으며 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];
}
에서 : 여기
는 코드입니다.