原点和目标点未精确放置在Google Maps SDK上

时间:2017-03-19 13:22:51

标签: ios google-maps google-direction

我试图在iOS上绘制一条来自Google Direction API的Google地图路线。 我点到了这个终点

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

然后我得到了我用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;

看起来起始线不是以其坐标开始,而是以最近的方式开始。见下图。

google direction

是否可以从其坐标绘制线条到#34;起始方向"?如果是这样,任何帮助将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:0)

您需要从google方向结果的起点和mapView中的实际起点绘制折线。

GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(actualLat,actualLon)];
[path addCoordinate:CLLocationCoordinate2DMake(startLat,startLon)];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];