Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create GMSPath with latitude and longitude I already have instead of pathFromEncodedPath?

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;}
like image 992
durazno Avatar asked Jan 07 '23 17:01

durazno


1 Answers

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];
like image 132
chirag shah Avatar answered Jan 13 '23 12:01

chirag shah