Google地图折线不完美 [英] Google maps polyline not rendering perfectly

查看:179
本文介绍了Google地图折线不完美的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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




这是放大时如何显示折线


这就是它缩小时的样子



这里是我绘制折线的函数

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

我为RCPolyline覆盖 init:是这样的

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

drawPolylineFromPoint :toPoint:是否做到这一点

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


解决方案

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



这个:

   - (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;}

现在我正在调用此方法

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

PS: RCPolyline GMSPolyline


的子类

I am drawing polyline using latest google maps API for iOS. I am constructing polyline point by point but it is not rendering properly as when i zoom out the polyline vanishes(not in literal terms) from the map and when i zoom in it simply shows the line.

This is how polyline appears when zoomed in

This is how it appears when zoomed out

here is my function for drawing polyline

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

i have override init: for RCPolyline to be something like this

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

and drawPolylineFromPoint:toPoint: does this

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

解决方案

I found the glitch, i was making local instance of RCPolyline class and was calling the method for constructing polyline from that what i wanted was to have a global object for RCPolyline instance and update the GMSPath for the RCPolyline class instance

something like this:

- (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;}

and now i am calling this method from that same instance.

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

PS: RCPolyline is subclass of GMSPolyline

这篇关于Google地图折线不完美的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆