ios – Google地图折线不完美呈现

前端之家收集整理的这篇文章主要介绍了ios – Google地图折线不完美呈现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用最新的Google Maps API for iOS绘制折线.我正在逐点构造折线,但是当我缩小折线从地图中消失(不是字面上的术语)时,它不能正常渲染,当我放大时,它只会显示线条.


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


这是缩小时的显示方式

这里是我绘制折线的功能

  1. RCPolyline *polyline = [[RCPolyline alloc] init];
  2. [polyline drawPolylineFromPoint:self.selectedEmployee.location toPoint:location];

我有覆盖init:为RCPolyline是这样的东西

  1. - (instancetype)init {
  2. self = [super init];
  3. if (self) {
  4. self.strokeWidth = 5.0f;
  5. self.strokeColor = UIColor.redColor;
  6. self.geodesic = YES;
  7. self.map = [RCMapView sharedMapView];
  8. }
  9. return self;}

和drawPolylineFromPoint:toPoint:这样做

  1. - (void)drawPolylineFromPoint:(CLLocation *)pointX toPoint:(CLLocation *)pointY {
  2. GMSMutablePath *path = [GMSMutablePath path];
  3. [path addCoordinate:pointX.coordinate];
  4. [path addCoordinate:pointY.coordinate];
  5. self.path = path;}

解决方法

我发现这个故障,我正在制作RCPolyline类的本地实例,并且正在调用构建折线的方法,我想要的是为RCPolyline实例提供一个全局对象,并为RCPolyline类实例更新GMSPath

这样的:

  1. - (instancetype)initWithMap:(GMSMapView *)mapView {
  2. self = [super init];
  3. if (self) {
  4. self.strokeWidth = 4.0f;
  5. self.strokeColor = [UIColor redColor];
  6. self.geodesic = YES;
  7. self.map = mapView;
  8. self.mutablePath = [GMSMutablePath path];
  9. }
  10. return self;}

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

  1. - (void)appendPolylineWithCoordinate:(CLLocation *)location {
  2. [self.mutablePath addCoordinate:location.coordinate];
  3. self.path = self.mutablePath;}

PS:RCPolyline是GMSPolyline的子类

猜你在找的iOS相关文章