继承BMKPointAnnotation类,并进行重写,在初始化的时候增加移动通知,在后台给过经纬度的同时并发送该通知对图标进行移动,若同一地图上有多个图标,根据图标的ID进行判断
[locations addObject:location];
if (locations.count >= 1 && movingOver == YES) {
moveArray = [NSArray arrayWithArray:locations];
[locations removeAllObjects];
// NSLog(@"----- moveArrayCount: %ld",moveArray.count);
// NSLog(@"------beging moving -----");
currentIndex = 0;
movingOver = NO;
[self startMoving];
}
- (void)startMoving
{
NSInteger index = currentIndex % moveArray.count;
CLLocation *newLocation = moveArray[index];
CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:self.coordinate.latitude longitude:self.coordinate.longitude];
double distance = [newLocation distanceFromLocation:currentLocation];
double speed = newLocation.speed;
CLLocationCoordinate2D newCoordinate = newLocation.coordinate;
[UIView animateWithDuration:distance/speed animations:^{
self.coordinate = newCoordinate;
currentIndex ++;
} completion:^(BOOL finished) {
if (currentIndex == moveArray.count) {
movingOver = YES;
moveArray = nil;
} else {
[self startMoving];
}
}];
}