1

I tried to draw a route with Google Maps on iOS that come from Google Direction API. I hit this end point

NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/directions/json?origin=%@&destination=%@&mode=driving&key=%@", origin, destination, gDirectionKey];

Then I got its routes that I draw with GMSPolyline

GMSPath *path =[GMSPath pathFromEncodedPath:resultData[@"routes"][0][@"overview_polyline"][@"points"]];
if (routeToCustomer == nil)
    routeToCustomer = [[GMSPolyline alloc] init];
routeToCustomer.path = path;
routeToCustomer.strokeWidth = 7;
routeToCustomer.strokeColor = [UIColor colorWithHexString:ACTIVE_COLOR];
routeToCustomer.map = _mapView;

It looks like that the starting line doesn't start in its coordinate, but in the nearest way. See image below.

google direction

Is it possible to draw line from its coordinate into "starting direction"? If so, any help would be appreciated. Thank you.

Sonic Master
  • 1,238
  • 2
  • 22
  • 36

1 Answers1

0

You will need draw a polyline from starting point of google direction result and actual starting point in mapView.

GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(actualLat,actualLon)];
[path addCoordinate:CLLocationCoordinate2DMake(startLat,startLon)];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
nikdange_me
  • 2,949
  • 2
  • 16
  • 24