I am using map on my application, For pin drop, I want to set user's image instead of default pin.
I am downloading users image and setting it as per code I paste below.
For different scale of devices I am using image name as per device scale like eg.,
1 For non retina device - pin.png (size 30 x 30)
2 For retina devices - pin@2x.png (size 60 x 60)
3 For 6+ device - pin@3x.png (size 90 x 90)
Here for 1 and 2 working fine and image loads perfect But for 6+ (3x scale) it's not working
What's issue is:
For 6+ I am downloading pin@3x image, But on map it's size is 90 x 90 that should be 30 x 30. As it simply works for images when we use from application bundle.
For pin@2x.png it works fine and shows 2x image in size 30 x 30.
I also tried below solution by setting scale of image but not works
MKPinAnnotationView: Are there more than three colors available?
I have tried my best to explain actual issue, Can any one guide please if I am missing any thing or if it's require to set anything?
Code
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *annotationView = nil;
if ([annotation isKindOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isKindOfClass:[KPAnnotation class]])
{
//Custom annotation class for pin drop
KPAnnotation *a = (KPAnnotation *)annotation;
annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
if (annotationView == nil)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:[a.annotations anyObject]
reuseIdentifier:@"pin"];
}
//Image View to add subview in MKPinAnnotationView
UIImageView *imageView = [[UIImageView alloc] init];
UIImage * image = [UIImage imageNamed:@"pin.png"];
imageView.image=image;
//Test URL - see image name here
NSString *readAWSURL=@"<domainname.com>/pin@3x.png";
//Downloading image here to load with async way (SDWebImage)
[imageView sd_setImageWithURL:[NSURL URLWithString:readAWSURL] placeholderImage:[UIImage imageNamed:@"pin.png"]];
annotationView.image=imageView.image;
[annotationView addSubview:imageView];
annotationView.canShowCallout = YES;
}
return annotationView;
}