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;}
In the Google Cloud Console, go to the Map Styles page. Select the style you want, and click Customize Style.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With