Google Maps SDK for iOS and Routes

I read the Google Maps SDK documentation for iOS, and I did not see anything about drawing directions on the map.

I know that polylines are available, but I do not think the best aproach.

Is it possible?

+7
source share
6 answers

There are some things in the library that are not in the documentation, so if you are looking for a function, you should download the SDK and look at the headers.

However, in the current version 1.0.2, I do not see anything for routing - either searching for a route, or drawing it (or even searching for addresses). At the moment, your only option is probably to use some other Google API to find the route, and then, as Lee said, use polylines to draw them.

+3
source

The iOS SDK does not yet support directions. In the meantime, you can use the Directions API Web services and make the route yourself using GMSPolyline.

You must also specify a function request to add this to the SDK.

+5
source

As Saxon Drus says, you can use the Google Maps Directions web service to find the route and draw them in polylines. This episode shows you how to implement it, and you can download sample code from this github repository .

+4
source

I had a similar problem, I needed the direction path to be drawn on a Google map using the same google ios sdk maps. I made access to the Google Distance API .

I extracted html_instructions and end_location from the API using the following code.

I had these variables defined as a property

@property NSMutableArray *detailedSteps; @property (strong, nonatomic) IBOutlet GMSMapView *mapview; 

And the following code to extract end_location and html_instructions

 NSURL *url=[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/json?origin=ahmedabad&destination=%@",self.city]]; NSURLResponse *res; NSError *err; NSData *data=[NSURLConnection sendSynchronousRequest:[[NSURLRequest alloc] initWithURL:url] returningResponse:&res error:&err]; NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSArray *routes=dic[@"routes"]; NSArray *legs=routes[0][@"legs"]; NSArray *steps=legs[0][@"steps"]; NSMutableArray *textsteps=[[NSMutableArray alloc] init]; NSMutableArray *latlong=[[NSMutableArray alloc]init]; for(int i=0; i< [steps count]; i++){ NSString *html=steps[i][@"html_instructions"]; [latlong addObject:steps[i][@"end_location"]]; [textsteps addObject:html]; } self.detailedSteps=textsteps; [self showDirection:latlong]; 

And here is my showDirection method, which draws a polygon on a map. Here I pass the latlong array. This is actually an array of end_location.

 -(void)showDirection:(NSMutableArray*) latlong{ GMSMutablePath *path = [GMSMutablePath path]; for(int i=0; i<[latlong count]; i++){ double lat=[latlong[i][@"lat"] doubleValue]; double lng=[latlong[i][@"lng"] doubleValue]; [path addLatitude:lat longitude:lng]; } NSLog(@"Direction path"); GMSPolyline *polyline = [GMSPolyline polylineWithPath:path]; polyline.strokeColor = [UIColor blueColor]; polyline.strokeWidth = 5.f; polyline.map = self.mapview ; } 
+2
source

Even version 1.1.0 does not implement any route tools, so I would recommend using URL schemes for better performance.

+1
source

I think you can now draw routes / directions using the Google Maps iOS SDK .
Follow the official video tutorial here:
http://talkminer.com/viewtalk.jsp?videoid=AdV7bCWuDYg&q=&row=4&N=5#.Ui2H1mSAZTE

+1
source

All Articles