Questions tagged [mkannotation]

An Apple protocol, for model object representing a point on a map view

An object that adopts this MKAnnotation protocol manages the data that you want to display on the map surface. It does not provide the visual representation displayed by the map. Instead, your map view either registers particular classes for annotations or the delegate provides the MKAnnotationView objects needed to display the content of your annotations. When you want to display content at a specific point on the map, add an annotation object to the map view. When the annotation’s coordinate is visible on the map, the map view asks its delegate to provide an appropriate view to display any content associated with the annotation.

There is basic MKPointAnnotation class that is useful if you do not need to add your own custom properties to an annotation.

If you do implement your own object to conform to MKAnnotation, there are a few considerations:

  1. If you want your map to respond to changes to the coordinate, title, or subtitle of the annotation object, make sure to make these conform to KVO (e.g., in Swift, declare them as dynamic).

  2. Probably obvious, but if the annotation views are configured to be draggable, you will want to make the coordinate mutable.

See also

1277 questions
14
votes
3 answers

Multiple annotation callouts displaying in MKMapView

Is it possible to open simultaneously more then one callout? The code: - (void)mapViewDidFinishLoadingMap:(MKMapView *)theMapView { for (id currentAnnotation in theMapView.annotations) { [theMapView…
user207128
14
votes
3 answers

MKMapView annotation is not selectable second time

On my iPad app I am using iOS map to display few points using annotation. I want to display custom callout too when an annotation is been selected. I am using UIPopoverController to show callout. However this works only when first time tap on…
Chinthaka
  • 966
  • 1
  • 13
  • 42
14
votes
6 answers

How to create an NSMutableArray and assign a specific object to it?

I am just getting into Obj C, and I am looking to create an array of MKAnnotations. I have already created the MKAnnotation class called TruckLocation that contains the name, description, latitude, and longitude. Here is what I have so far for the…
novicePrgrmr
  • 18,647
  • 31
  • 81
  • 103
14
votes
6 answers

Drag an annotation pin on a mapview

The annotation pin is draggable but I couldn't drop it to the destination location. The problem is how could I get the destination location's coordinate where i drop the annotation pin? Any method exist? Edit 1: The center of the annotation pin…
lu yuan
  • 7,207
  • 9
  • 44
  • 78
13
votes
2 answers

Animate removal of annotations

I have a map and a set of annotations, each with a 'parent' property. Currently when I add annotations I implement the didAddAnnotationViews method to animate those annotations so they appear to come from their parent's coordinate. Is there a way of…
benwad
  • 6,414
  • 10
  • 59
  • 93
13
votes
1 answer

Customizing the MKAnnotation Callout bubble

I have a requirement in my application map page. I have to customize the Callout bubbles. I need to add an image, two labels and a button with specific height and width of each. I have gone through web and could not find a proper link that explains…
sbmandav
  • 1,211
  • 3
  • 16
  • 25
12
votes
1 answer

how to set up array for multi annotations with swift

How should the array below be set. Im trying to add multiple annotations onto my map. I was able to find the code below on stackoverflow but they did not show how to set up the array. var objects = [ //how should the array be setup…
ThisISswift
  • 305
  • 2
  • 4
  • 14
12
votes
7 answers

iOS refresh annotations on mapview

I have a mapview where the annotation's coordinates are constantly being updated but when I use setCoordinate, the annotation does not move. How do I refresh the annotations to reflect their coordinates? - (void)updateUnits { PFQuery *query =…
Jon Erickson
  • 1,876
  • 4
  • 30
  • 73
11
votes
2 answers

Grouped/Ungroup MKAnnotation depending on the zoom level (And keep it fast)

I have a mapview that has a lot of annotations, most of them are very close to each other. What I want to do is similar to the Photo app on iOS where annotations are grouped when they are too close to each other and whenever you zoom out, they un…
Pier-Olivier Thibault
  • 3,907
  • 2
  • 33
  • 33
10
votes
3 answers

Custom image for MKAnnotation

I have created an annotation which I'm adding to an MKMapView. How would I go about having a custom image instead of the standard red pin? @interface AddressAnnotation : NSObject { CLLocationCoordinate2D coordinate; NSString…
3sl
  • 295
  • 2
  • 4
  • 7
10
votes
2 answers

How do I update the location of an MKAnnotation object on a mapView?

I have the following code, which aims to loop through all the annotations on the current apple map view and update their location coordinates. for existingMarker in self.mapView.annotations { existingMarker.coordinate.latitude = 12.12121212 …
sometimesiwritecode
  • 2,993
  • 7
  • 31
  • 69
9
votes
3 answers

iOS MapKit Changing mapview maptype causes annotation image to change to pin?

Any suggestions on what is wrong with the following would be appreciated. I am adding a custom image to an annotation using the following code. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id…
jimsis
  • 301
  • 4
  • 15
9
votes
2 answers

Mkmap iOS11 clusters doesn't split up after max zoom, how to set it up?

First, my code is perfectly running. I have well set up and mapView.register my annotation markers and cluster. When I zoom out the annotations fusion as expected in my cluster views, when I zoom in, same good result, except at a certain point. When…
Cory
  • 341
  • 6
  • 15
9
votes
3 answers

iphone mapview bring first and last annotation to the front

I need some code which can be used outside of the mk* functions. I need to run my custom function to bring the FIRST and LAST markers in an array to the front. (so on top of all the other markers on my screen). I have tried [self.view…
Matt Facer
  • 3,103
  • 11
  • 49
  • 91
9
votes
2 answers

Get frame of annotation on map view

In my app I have custom annotations where the leftCalloutAccessoryView is a circular UIView. This works perfectly in the simulator with this code: let rideTimeView = UIView() rideTimeView.frame = CGRectMake(5, 5, 50, 50) …
user3746428
  • 11,047
  • 20
  • 81
  • 137
1 2
3
85 86