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

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

}

}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。