Manish Jain
Manish Jain

Reputation: 865

Mapview annotation adjustment

HI all i am trying to change the image of annotation when user walk in following code

- (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];
    }

}

But i am unable to change annotation image please tell me why i am not able to do it

Upvotes: 0

Views: 459

Answers (2)

visakh7
visakh7

Reputation: 26390

I don't think this code has any connection with the map view and u are allocating a new instance of MKAnnotationView with the new image. This doesn't change the existing ones which you already have on the map. What you need to do is check the distance in mapview's view for annotation and then change its image there.

Upvotes: 0

saadnib
saadnib

Reputation: 11145

You can make your custom annotation follow the tutorial

http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/

Upvotes: 2

Related Questions