将已添加的注释移动到NewLocation

时间:2013-09-14 14:15:21

标签: iphone ios mkmapview mapkit core-location

我想将添加的注释移动到newlocation,下面是代码,而在其他部分我想要这样做:

在之前的代码中,添加了新注释并删除了之前的注释,但它会受到方向程度的影响。所以,我想移动注释而不添加新的注释。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (newLocation.horizontalAccuracy < 0)
        return;
    if  (!newLocation)
        return;

    static BOOL annotationAdded = NO;

    self.currentLocation = newLocation;
    self.previousLocation = oldLocation;

    if(self.currentLocation != nil)
    {
        CLLocationCoordinate2D location = CLLocationCoordinate2DMake(self.currentLocation.coordinate.latitude, self.currentLocation.coordinate.longitude);
        myAnnotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"Current Location" subTitle:nil];
        if (!annotationAdded)
        {
            annotationAdded = YES;
            [self.myMapView addAnnotation:myAnnotation];
        }
        else
        {
            // Here i want to move added annotation to newlocation coordinates 

        }

    }
}

1 个答案:

答案 0 :(得分:0)

它的工作方式是,您使用注释为地图提供信息,然后它会触发在屏幕上绘制注释的功能。一旦它出现在屏幕上,基本上没有办法移动注释,而是删除它并添加一个带有新坐标的新注释。