0

I am trying to display some icons on a MKMapView. I have achieved that by using this code:

MapPoint *placeObject = [[MapPoint alloc] initWithName:place.name
                                                           address:place.address
                                                        coordinate:place.location.coordinate
                                                             image:place.customMapPinImage
                                                              icon:place.icon
                                                          bookmark:place.bookmark
                                                       contents_ID:place.contents_ID
                                             contents_lang_MAIN_ID:place.contents_lang_MAIN_ID
                                               contents_lang_ID_ML:place.contents_lang_ID_ML];


            [mapView addAnnotation:placeObject];

The problem is that, without changing anything in the code, the size of the icons changed and I don't know why. How can I adjust the size of the icons?

Rengers
  • 14,911
  • 1
  • 36
  • 54
Steve
  • 1
  • 4
  • Possible duplicate of [Size image pin annotation](https://stackoverflow.com/questions/33262759/size-image-pin-annotation) – Kosuke Ogawa Dec 15 '18 at 14:10

1 Answers1

0

You need to write class annotations

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface Annotation : NSObject <MKAnnotation>

@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (strong, nonatomic) NSString *myTitle;

+ (Annotation *)initAnnotation:(CLLocationCoordinate2D)coordinate title:(NSString *)title;

@end

Implementation

#import "Annotation.h"

@implementation Annotation

+ (Annotation *)initAnnotation:(CLLocationCoordinate2D)coordinate title:(NSString *)title

{
    return [[Annotation alloc] initWithAnnotation:coordinate title:title];
}

- (instancetype)initWithAnnotation:(CLLocationCoordinate2D)coordinate title:(NSString *)title
{
     self = [super init];
     self.coordinate = coordinate;
     self.myTitle = title;
     return self;
}

@end

ViewController

#import "ViewController.h"
#import <MapKit/MapKit.h>
#import "Annotation.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet MKMapView *mapView;

@end

@implementation ViewController

- (void)viewDidLoad {
   [super viewDidLoad];

   //set coordinates

   CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(51.50851, -0.02172);

   //add annotation

   Annotation *annotation = [Annotation initAnnotation:coordinate title:@"Annotation"];

   [self.mapView addAnnotation:annotation];
   [self.mapView showAnnotations:@[annotation] animated:YES];

   // add circle with radius

   MKCircle *circle = [MKCircle circleWithCenterCoordinate:annotation.coordinate radius:10000];
   [self.mapView addOverlay:circle];

   //add region by coordinates

   MKCoordinateRegion region;
   region.center.latitude = 51.50851;
   region.center.longitude = -0.02172;

   // level zoom

   region.span.latitudeDelta = 1;
   region.span.longitudeDelta = 1;
   region = [self.mapView regionThatFits:region];

   [self.mapView setRegion:region animated:YES];
}

Do not forget to set the controller as a map delegate, and implement the circle mapping method

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>) overlay{
   MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
   circleView.fillColor = [[UIColor greenColor] colorWithAlphaComponent:0.4];
   return circleView;
}[![enter image description here][1]][1]

Pin appears, and you can adjust its size

https://prntscr.com/lvfjwi

Sasha Tsvigun
  • 311
  • 5
  • 15