How to Get Animated Polyline Route in Gmsmapview, So That It Move Along with Map When Map Is Moved

How to get animated polyline route in GMSMapView, so that it move along with map when map is moved?

I am create GMSPath animation with path coordinate

Sample Image

Objective C

interface

@interface MapWithTracking () 

@property (weak, nonatomic) IBOutlet GMSMapView *mapView;

@property (nonatomic,strong) GMSMutablePath *path2;

@property (nonatomic,strong)NSMutableArray *arrayPolylineGreen;

@property (nonatomic,strong) GMSPolyline *polylineBlue;

@property (nonatomic,strong) GMSPolyline *polylineGreen;

@end

implementation

-(void)viewDidLoad {
_arrayPolylineGreen = [[NSMutableArray alloc] init];
_path2 = [[GMSMutablePath alloc]init];
}

Get a GMSPath and create a blue polyline.

-(void)createBluePolyline(GMSPath *path) {

// Here create a blue poly line
_polylineBlue = [GMSPolyline polylineWithPath:path];
_polylineBlue.strokeColor = [UIColor blueColor];
_polylineBlue.strokeWidth = 3;
_polylineBlue.map = _mapView;

// animate green path with timer
[NSTimer scheduledTimerWithTimeInterval:0.003 repeats:true block:^(NSTimer * _Nonnull timer) {
[self animate:path];
}];

}

Animate a Green Polyline

Adding coordinate to path 2 and assign to map

-(void)animate:(GMSPath *)path {

dispatch_async(dispatch_get_main_queue(), ^{
if (i < path.count) {
[_path2 addCoordinate:[path coordinateAtIndex:i]];
_polylineGreen = [GMSPolyline polylineWithPath:_path2];
_polylineGreen.strokeColor = [UIColor greenColor];
_polylineGreen.strokeWidth = 3;
_polylineGreen.map = _mapView;
[arrayPolylineGreen addObject:_polylineGreen];
i++;
}
else {
i = 0;
_path2 = [[GMSMutablePath alloc] init];

for (GMSPolyline *line in arrayPolylineGreen) {
line.map = nil;
}

}
});
}

How do I show a polyline that only connects 2 points?

The problem is that your two points aren't just two arbitrary points and there isn't just one shortest line between them.

Points (90, X) and (-90, X) are the north and south poles no matter the value of X, and there are infinite lines that connect them. I'd suggest adding the point on the equator (0, X) between the other two points.

I added a point on the equator between the north pole and south pole and now it only drew a line to the equator.

I can't explain that. Seems like a bug. Try values near the poles such as 89 and -89 or 89.999 and -89.999.



Related Topics



Leave a reply



Submit