谷歌地图折线无法完美呈现

Nit*_*ija 12 google-maps objective-c google-maps-api-3 ios

我正在使用最新的谷歌地图API for iOS绘制折线.我正在逐点构建折线,但它不能正确渲染,因为当我缩小折线时,从地图上消失(不是字面意义),当我放大它只是显示线条.

放大视野 这是折线放大时折线的显示方式

缩小视野 这是缩小时的显示方式

这是我绘制折线的功能

RCPolyline *polyline = [[RCPolyline alloc] init];
[polyline drawPolylineFromPoint:self.selectedEmployee.location toPoint:location];
Run Code Online (Sandbox Code Playgroud)

init:对RCPolyline的覆盖是这样的

- (instancetype)init {
self = [super init];
if (self) {
    self.strokeWidth = 5.0f;
    self.strokeColor = UIColor.redColor;
    self.geodesic = YES;
    self.map = [RCMapView sharedMapView];
}
return self;}
Run Code Online (Sandbox Code Playgroud)

drawPolylineFromPoint:toPoint:做到这一点

 - (void)drawPolylineFromPoint:(CLLocation *)pointX toPoint:(CLLocation *)pointY {
      GMSMutablePath *path = [GMSMutablePath path];
      [path addCoordinate:pointX.coordinate];
      [path addCoordinate:pointY.coordinate];
      self.path = path;} 
Run Code Online (Sandbox Code Playgroud)

Nit*_*ija 4

我发现了问题,我正在创建RCPolyline类的本地实例,并调用构造折线的方法,我想要的是为 RCPolyline 实例创建一个全局对象,并GMSPathRCPolyline类实例更新

像这样的东西:

- (instancetype)initWithMap:(GMSMapView *)mapView {
    self = [super init];
    if (self) {
      self.strokeWidth = 4.0f;
      self.strokeColor = [UIColor redColor];
      self.geodesic = YES;
      self.map = mapView;
      self.mutablePath = [GMSMutablePath path];
    }
      return self;}
Run Code Online (Sandbox Code Playgroud)

现在我从同一个实例调用这个方法。

- (void)appendPolylineWithCoordinate:(CLLocation *)location {
    [self.mutablePath addCoordinate:location.coordinate];
    self.path = self.mutablePath;}
Run Code Online (Sandbox Code Playgroud)

PS:RCPolyline是的子类GMSPolyline