美文网首页
百度地图根据经纬度变化,图标进行移动

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

作者: 嘚嘚以嘚嘚 | 来源:发表于2017-12-04 11:03 被阅读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];

    }

    }];

    }

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/heitixtx.html