Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps polyline not rendering perfectly

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.

Zoomed in view This is how polyline appears when zoomed in

Zoomed out view 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;} 
like image 641
Nitish Makhija Avatar asked Feb 25 '17 10:02

Nitish Makhija


People also ask

How do I make Google maps look better?

In the Google Cloud Console, go to the Map Styles page. Select the style you want, and click Customize Style.

What is polyline in mapping?

A polyline is a list of points, where line segments are drawn between consecutive points. A polyline has the following properties: Points. The vertices of the line. Line segments are drawn between consecutive points.


1 Answers

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

like image 129
Nitish Makhija Avatar answered Sep 18 '22 08:09

Nitish Makhija