Mapview注释调整

时间:2011-03-25 08:44:43

标签: iphone ios mapkit mkmapview mkannotationview

我试图在用户走进以下代码时尝试更改注释图像

- (void)locationManager:(CLLocationManager *)manager   didUpdateToLocation:(CLLocation *)newLocation  fromLocation:(CLLocation *)oldLocation
{
    for (int i = 0; i < [_annotationArray count]; i++)
    {
        //MKAnnotation xxx = [_annotationArray objectAtIndex:i];

        Shadows* shadowObj2 = [_shadowArray objectAtIndex:i];

        NSLog(@"%@",_shadowArray);

        CLLocationCoordinate2D location3;

        location3.latitude  =  [shadowObj2.position_x floatValue];
        location3.longitude =  [shadowObj2.position_y floatValue];

        CLLocation* locationold = [[CLLocation alloc] initWithLatitude:location3.latitude longitude:location3.longitude];

        CLLocationDistance kilometers = [newLocation distanceFromLocation:locationold];

        //temp = [kilometers intValue];

        if (kilometers > 50 && kilometers <100)
        {
            MKAnnotationView* newA = [[MKAnnotationView alloc] initWithAnnotation:[_annotationArray objectAtIndex:i] reuseIdentifier:@"annotation1"];
            newA.image = [UIImage imageNamed:@"shadowS.png"];
            newA.canShowCallout = YES;
        }

        [locationold release];
        //[shadowObj2 release];
    }

}

但是我无法更改注释图像,请告诉我为什么我无法做到这一点

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

我不认为此代码与地图视图有任何关联,并且您正在使用新图像分配MKAnnotationView的新实例。这不会改变您在地图上已有的现有属性。您需要做的是检查mapview视图中的注释距离,然后在那里更改其图像。