I've been following this tutorial that helps me draw route directions(polyline) between 2 tapped places on map. However I don't need to get tapped locations since by the time I want to show user the route, I'll already have latitude and longitude of origin and destination.
Can I create GMSPath with an array of latitude and longitude I already have? If so, how..?
- (void)addDirections:(NSDictionary *)json {
NSDictionary *routes = [json objectForKey:@"routes"][0];
NSDictionary *route = [routes objectForKey:@"overview_polyline"];
NSString *overview_route = [route objectForKey:@"points"];
GMSPath *path = [GMSPath pathFromEncodedPath:overview_route];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.map = self.mainGoogleMap;}
Yes you can do it via following method.
First you need to create NSMutablePath global object.
Then you have to add latitude and longitude in that path like below and then assign that path to polyline object and your polyline is drawn
In viewDidLoad
pathDynamic = [[GMSMutablePath alloc] init];
When you want to add the location in mutable path
CLLocation *loc = [[CLLocation alloc] initWithLatitude:[[dictData valueForKey:@"fl_route_latitude"] doubleValue] longitude:[[dictData valueForKey:@"fl_route_longitude"] doubleValue]];
[pathDynamic addCoordinate:loc.coordinate];//Add your location in mutable path
GMSPolyline *polyline = [GMSPolyline polylineWithPath:pathDynamic];
// Add the polyline to the map.
polyline.strokeColor = AppOrangeColor;
polyline.strokeWidth = 3.0f;
polyline.map = [self getMapView];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With