Commit 1251bd05 authored by lmj_521aiau@163.com's avatar lmj_521aiau@163.com

no message

parent 4c5ea2b7
...@@ -139,7 +139,9 @@ ...@@ -139,7 +139,9 @@
///初始化地图 ///初始化地图
self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码 ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
_mapView.showsUserLocation = false; // _mapView.showsUserLocation = false;
_mapView.showsUserLocation = YES;
_mapView.userTrackingMode = MAUserTrackingModeFollow;
_mapView.delegate = self; _mapView.delegate = self;
_mapView.showsScale = false; _mapView.showsScale = false;
_mapView.showsCompass = false; _mapView.showsCompass = false;
...@@ -179,18 +181,21 @@ ...@@ -179,18 +181,21 @@
mapPaddle = YES; mapPaddle = YES;
} }
- (void)drawLineAction1{ - (void)drawLineAction{
//重制
// _endAnnotationView = nil; // _endAnnotationView = nil;
// _startAnnotationView = nil; // _startAnnotationView = nil;
[self.mapView removeOverlays:self.mapView.overlays];
[self.mapView removeAnnotations:self.mapView.annotations]; [self.mapView removeAnnotations:self.mapView.annotations];
_trackAnimation = YES; _trackAnimation = YES;
//动画行动点
endAnnotation = [[ZJCustomAnnotation alloc] init]; endAnnotation = [[ZJCustomAnnotation alloc] init];
[_mapView addAnnotation:endAnnotation]; [_mapView addAnnotation:endAnnotation];
//动画 路径 数据处理
_smoothTrackCount = _locations.count; _smoothTrackCount = _locations.count;
_smoothTrackPoints = malloc(sizeof(CLLocationCoordinate2D)*_smoothTrackCount); _smoothTrackPoints = malloc(sizeof(CLLocationCoordinate2D)*_smoothTrackCount);
velocity = malloc(sizeof(float)*_smoothTrackCount); velocity = malloc(sizeof(float)*_smoothTrackCount);
...@@ -206,8 +211,31 @@ ...@@ -206,8 +211,31 @@
_smoothTrackPoints[i] = coordinate; _smoothTrackPoints[i] = coordinate;
} }
} }
//构造折线数据对象
CLLocationCoordinate2D commonPolylineCoords[self.locations.count];
for (int i = 0 ; i < self.locations.count; i++) {
commonPolylineCoords[i].latitude = self.locations[i].latitude;
commonPolylineCoords[i].longitude = self.locations[i].longitude;
}
//构造折线对象
MKPolyline *commonPolyline = [MKPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count];
self.commonPolyline = commonPolyline;
//在地图上添加折线对象
[self.mapView addOverlay: self.commonPolyline];
MKMapRect rect = MKMapRectMake(self.commonPolyline.boundingMapRect.origin.x, self.commonPolyline.boundingMapRect.origin.y, self.commonPolyline.boundingMapRect.size.width, self.commonPolyline.boundingMapRect.size.height);
[self.mapView setVisibleMapRect:rect edgePadding:UIEdgeInsetsMake(250, 50, 50, 50) animated:true];
if (!mapPaddle) {
[self addAnimation];
}
} }
//开始动画
- (void)addAnimation{ - (void)addAnimation{
_container = (UIView *)[self.mapView.subviews firstObject].subviews.lastObject; _container = (UIView *)[self.mapView.subviews firstObject].subviews.lastObject;
...@@ -247,7 +275,7 @@ ...@@ -247,7 +275,7 @@
_trackAnimation = NO; _trackAnimation = NO;
mapPaddle = NO; mapPaddle = NO;
} }
//动画结束
- (void)removeLayer{ - (void)removeLayer{
_mapView.userInteractionEnabled = YES; _mapView.userInteractionEnabled = YES;
[self.trackTimeView.trackButton setSelected:false]; [self.trackTimeView.trackButton setSelected:false];
...@@ -261,40 +289,9 @@ ...@@ -261,40 +289,9 @@
[self.mapView addAnnotation:(id<MKAnnotation>)_startAnnotation]; [self.mapView addAnnotation:(id<MKAnnotation>)_startAnnotation];
} }
- (void) drawLineAction {
[self.mapView removeOverlays:self.mapView.overlays];
//构造折线数据对象
CLLocationCoordinate2D commonPolylineCoords[self.locations.count];
for (int i = 0 ; i < self.locations.count; i++) {
commonPolylineCoords[i].latitude = self.locations[i].latitude;
commonPolylineCoords[i].longitude = self.locations[i].longitude;
}
//构造折线对象
MKPolyline *commonPolyline = [MKPolyline polylineWithCoordinates:commonPolylineCoords count:self.locations.count];
self.commonPolyline = commonPolyline;
//在地图上添加折线对象
[self.mapView addOverlay: self.commonPolyline];
MKMapRect rect = MKMapRectMake(self.commonPolyline.boundingMapRect.origin.x, self.commonPolyline.boundingMapRect.origin.y, self.commonPolyline.boundingMapRect.size.width, self.commonPolyline.boundingMapRect.size.height);
[self.mapView setVisibleMapRect:rect edgePadding:UIEdgeInsetsMake(250, 50, 50, 50) animated:true];
if (!mapPaddle) {
[self addAnimation];
}
}
#pragma mark - Map Delegate #pragma mark - Map Delegate
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{ - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
mapPaddle = YES; mapPaddle = YES;
}
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered{
if (_trackAnimation) { if (_trackAnimation) {
[self addAnimation]; [self addAnimation];
} }
...@@ -418,14 +415,13 @@ ...@@ -418,14 +415,13 @@
} }
} }
} }
NSLog(@"%@", self.locations); NSLog(@"%@", self.locations);
if (_self.locations.count <= 0) { if (_self.locations.count == 0) {
[_self showAlertView]; [_self showAlertView];
return; return;
} }
[_self drawLineAction]; [_self drawLineAction];
[_self drawLineAction1];
}else{ }else{
[MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view]; [MBProgressHUD showError:[response objectForKey:@"msg"] toView:self.view];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment