繼承BMKPointAnnotation類胯究,并進行重寫,在初始化的時候增加移動通知躁绸,在后臺給過經(jīng)緯度的同時并發(fā)送該通知對圖標進行移動,若同一地圖上有多個圖標,根據(jù)圖標的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];
}
}];
}