百度地图根据经纬度变化,图标进行移动

2017-12-04  本文已影响0人  嘚嘚以嘚嘚

继承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];

}

}];

}

上一篇 下一篇

猜你喜欢

热点阅读