軌跡糾偏的作用就是去掉繪制路線時(shí)候兩個(gè)定位點(diǎn)之間產(chǎn)生的毛刺和尖角威鹿,使路線看起來(lái)更加的圓滑,正常
- (void) DrawLine{
CLLocationCoordinate2D coordinate;
CLLocation *location;
NSMutableArray * array = [NSMutableArray array];
for (int i = 0; i < self.locations.count; i++) {
coordinate.latitude = [self.latitudes[i] floatValue];
coordinate.longitude = [self.longitudes[i] floatValue];
location = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
[self.tempTraceLocations addObject:location];
[array addObject:location];
}
}
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
{
if ([overlay isKindOfClass:[MAPolyline class]])
{
MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
polylineRenderer.lineWidth = 4.0f;
polylineRenderer.strokeColor = KMainColor;
polylineRenderer.lineJoinType = kMALineJoinRound;
polylineRenderer.lineCapType = kMALineCapRound;
return polylineRenderer;
}
return nil;
}
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
if ([annotation isKindOfClass:[MAPointAnnotation class]]){
static NSString *pointReuseIndetifier = @"driverReuseIndetifier";
MAAnnotationView *annotationView = (MAAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
if (annotationView == nil){
annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:pointReuseIndetifier];
}
if (![annotation isKindOfClass:[MANaviAnnotation class]])
{
/* 起點(diǎn). */
if ([[annotation title] isEqualToString:(NSString*)RoutePlanningViewControllerStartTitle])
{
annotationView.image = [UIImage imageNamed:@"起點(diǎn)icon"];
//設(shè)置中心點(diǎn)偏移,使得標(biāo)注底部中間點(diǎn)成為經(jīng)緯度對(duì)應(yīng)點(diǎn)
annotationView.centerOffset = CGPointMake(0, -(CURRENT_SIZE(24)/2));
}
/* 終點(diǎn). */
else if([[annotation title] isEqualToString:(NSString*)RoutePlanningViewControllerDestinationTitle])
{
annotationView.image = [UIImage imageNamed:@"終點(diǎn)icon"];
//設(shè)置中心點(diǎn)偏移科雳,使得標(biāo)注底部中間點(diǎn)成為經(jīng)緯度對(duì)應(yīng)點(diǎn)
annotationView.centerOffset = CGPointMake(0, -(CURRENT_SIZE(24)/2));
}
}
return annotationView;
}
return nil;
}
#pragma mark -------------------- 軌跡糾偏 --------------------
- (void)queryTraceWithLocations:(NSArray<CLLocation *> *)locations withSaving:(BOOL)saving
{
NSMutableArray *mArr = [NSMutableArray array];
for(CLLocation *loc in locations)
{
MATraceLocation *tLoc = [[MATraceLocation alloc] init];
tLoc.loc = loc.coordinate;
tLoc.speed = loc.speed * 3.6; //m/s 轉(zhuǎn) km/h
tLoc.time = [loc.timestamp timeIntervalSince1970] * 1000;
tLoc.angle = loc.course;
[mArr addObject:tLoc];
}
__weak typeof(self) weakSelf = self;
__unused NSOperation *op = [self.traceManager queryProcessedTraceWith:mArr type:-1 processingCallback:nil finishCallback:^(NSArray<MATracePoint *> *points, double distance) {
NSLog(@"trace query done!");
[weakSelf addFullTrace:points];
} failedCallback:^(int errorCode, NSString *errorDesc) {
NSLog(@"Error: %@", errorDesc);
// weakSelf.queryOperation = nil;
}];
}
GitHub代碼下載地址
喜歡的記得給個(gè)Star
我是Renjiee 我要做最騷的程序猿??????