我在不同的数组中有20个纬度和20个经度。所以我想用这些点来绘制路线。有人能建议我怎么画从A到B&B到C&C到D……
您可以为坐标对使用Google Directions API,它将返回一个多段线字符串,您可以使用该字符串创建GMSPath(使用+pathFromEncodedPath:),然后您可以使用它在地图上创建GMSPolyline(使用+polylineWithPath:)。
使用此代码在标记列表中绘制多段线。annotations-NSMutableArray包含GMS标记对象。
- (void)drawLineSubroutine
{
GMSMutablePath *path = [GMSMutablePath path];
for (int i=0; i<annotations.count; i++)
{
GMSMarker *marker = [annotations objectAtIndex:i];
[path addCoordinate:CLLocationCoordinate2DMake(marker.position.latitude,marker.position.longitude)];
}
polyLine = [GMSPolyline polylineWithPath:path];
polyLine.strokeWidth = 1.0f;
polyLine.map = mapGoogle;
}