我正在使用獲取方向。通過此LINK幫助我繪製兩點之間的路線。現在我無法給出路線指令(例如:向左轉,轉向正確)給最終用戶。如何解決這個問題請幫助me.Now我使用下面的代碼如何知道谷歌地圖上兩個位置之間的每個路線位置iOS sdk
//Request the url
-(void)getWayPoints:(CLLocationCoordinate2D)origin destinationIS:(CLLocationCoordinate2D)desti{
NSString *oLat = [NSString stringWithFormat:@"%f",origin.latitude];
NSString *oLong = [NSString stringWithFormat:@"%f",origin.longitude];
NSString *dLat = [NSString stringWithFormat:@"%f",desti.latitude];
NSString *dLong = [NSString stringWithFormat:@"%f",desti.longitude];
NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?&origin=%@,%@&destination=%@,%@&sensor=false",oLat,oLong,dLat,dLong];
NSLog(@"url : %@", url);
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(
origin.latitude,
origin.longitude);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.map = mapView_;
CLLocationCoordinate2D position1 = CLLocationCoordinate2DMake(
desti.latitude,
desti.longitude);
GMSMarker *marker1 = [GMSMarker markerWithPosition:position1];
marker1.map = mapView_;
NSURL *googleRequestURL=[NSURL URLWithString:url];
NSLog(@"googleRequestURL : %@", googleRequestURL);
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
//Response from URL
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
// NSLog(@"responseData Data: %@", responseData);
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSArray* places = [json objectForKey:@"routes"];
NSDictionary *routes = [json objectForKey:@"routes"][0];
NSDictionary *route = [routes objectForKey:@"overview_polyline"];
NSArray *routes1 = [json objectForKey:@"routes"];
NSArray *legs = [routes1[0] objectForKey:@"legs"];
NSLog(@"legs %@", legs);
NSArray *steps = [legs[0] objectForKey:@"steps"];
NSString *overview_route = [route objectForKey:@"points"];
GMSPath *path = [GMSPath pathFromEncodedPath:overview_route];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeColor = [UIColor redColor];
polyline.strokeWidth = 5.f;
polyline.map = mapView_;
}