天天看點

android高德地圖軌迹糾偏,RoutePath-(高德地圖)根據定位點繪制路線+軌迹糾偏

軌迹糾偏的作用就是去掉繪制路線時候兩個定位點之間産生的毛刺和尖角,使路線看起來更加的圓滑,正常

android高德地圖軌迹糾偏,RoutePath-(高德地圖)根據定位點繪制路線+軌迹糾偏

IMG_0323.PNG

- (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 )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)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]])

{

if ([[annotation title] isEqualToString:(NSString*)RoutePlanningViewControllerStartTitle])

{

annotationView.image = [UIImage imageNamed:@"起點icon"];

//設定中心點偏移,使得标注底部中間點成為經緯度對應點

annotationView.centerOffset = CGPointMake(0, -(CURRENT_SIZE(24)/2));

}

else if([[annotation title] isEqualToString:(NSString*)RoutePlanningViewControllerDestinationTitle])

{

annotationView.image = [UIImage imageNamed:@"終點icon"];

//設定中心點偏移,使得标注底部中間點成為經緯度對應點

annotationView.centerOffset = CGPointMake(0, -(CURRENT_SIZE(24)/2));

}

}

return annotationView;

}

return nil;

}

#pragma mark -------------------- 軌迹糾偏 --------------------

- (void)queryTraceWithLocations:(NSArray *)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 轉 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 *points, double distance) {

NSLog(@"trace query done!");

[weakSelf addFullTrace:points];

} failedCallback:^(int errorCode, NSString *errorDesc) {

NSLog(@"Error: %@", errorDesc);

// weakSelf.queryOperation = nil;

}];

}

我是Renjiee 我要做最騷的程式猿👨‍💻‍