开发者

viewForAnnotation problem-Images are not placing properly on google map in iPhone

In my Application I have to show the google map along with pin images. I have to place two images according to the condition(branch,atm).In viewForAnnotation method I am doing code for the same,in NSLog I am getting the correct output but annotation images aren't placing properly. Images are placing inconsistently.Here is my code.

- (MKAnnotationView *) mapView:(MKM开发者_Go百科apView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{     
NSString* identifier = @"Pin";  
MKAnnotationView* annView = [searchMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
AddressAnnotation *delegate = annotation;  
Location *newLoc = [searchData objectAtIndex:countATMandBranch];
if (annView == nil) {
annView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"cell"]autorelease];
    annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];         
    if(newLoc.isATM == YES)
    {   
        annView.image = [UIImage imageNamed:@"map_atmicon.png"];
    }

    else if(newLoc.isBranch == YES)
    {   
        annView.image = [UIImage imageNamed:@"map_branchicon.png"];

    }
    //annView.enabled = YES;
    annView.tag = mapView.tag;
    annView.canShowCallout =YES;


}

countATMandBranch++;
return annView;

}

If any one aware of this kind of issue please reply to my question.


This might be an offset issue.

When you use a custom image for an MKAnnotationView it will by default position it in the center. If you are using a custom 'pin' image this isn't what you want - you want the bottom of the pin to point to the location, rather than the center. If you don't change the offset, when you zoom in/out the position of the annotation will appear to change in comparison to where you think it should be.

You should therefore make sure you've set an appropriate centerOffset on your annotation view. I don't see you setting it in the code above, so unless you want your image to be centered exactly on the coordinates required this is probably what's causing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜