Image Annotation Image Size

I put a personal image instead of a traditional red pin. When I open the map to display a pin, the image covers the entire map. Is there a maximum pin image size, or how can I integrate something into the code so that it matches the standard classic size pins?

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { if annotation is MKUserLocation { return nil } let annotationIdentifier = "SomeCustomIdentifier" // use something unique that functionally identifies the type of pin var annotationView: MKAnnotationView! = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier) if annotationView != nil { annotationView.annotation = annotation } else { annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) annotationView.image = UIImage(named: "pin maps.png") annotationView.canShowCallout = true annotationView.calloutOffset = CGPointMake(-8, 0) annotationView.autoresizesSubviews = true annotationView.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView } return annotationView } 
+7
ios swift2 xcode7 mapkit mkannotation
source share
1 answer

There is no maximum pin size. You need to resize the UIImage.

  let annotationIdentifier = "SomeCustomIdentifier" var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier) if annotationView == nil { annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) annotationView?.canShowCallout = true // Resize image let pinImage = UIImage(named: "pin maps.png") let size = CGSize(width: 50, height: 50) UIGraphicsBeginImageContext(size) pinImage!.drawInRect(CGRectMake(0, 0, size.width, size.height)) let resizedImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() annotationView?.image = resizedImage let rightButton: AnyObject! = UIButton(type: UIButtonType.DetailDisclosure) annotationView?.rightCalloutAccessoryView = rightButton as? UIView } else { annotationView?.annotation = annotation } 
+19
source share

All Articles