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
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
Images Not Showing Up When Architecture Set to 64 Bit
How to Convert an Int to a Character in Swift
Avcapturesession Audio Doesn't Work for Long Videos
Nsinternalinconsistencyexception, Reason: Could Not Load Nib in Bundle
Are View Controllers with Nib Files Broken in iOS 8 Beta 5
Sending a Private Message to Your Friends via Facebook iOS Sdk
Google Places Autocomplete on iOS - Can't Load Search Results - Try Again
iOS Automatically Add Hyphen in Text Field
Uitextfield -Webview No Longer Supported
Fbsdkloginmanager Loginwithpublishpermissions Always Returns Iscancelled=Yes
Split View Controller Must Be Root View Controller
Uitableviewcell Imageview Changing on Select
Swift/How to Use Dispatch_Group with Multiple Called Web Service
Code Signing Error: Application Failed Codesign Verification
Removing New Line Characters from Nsstring