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
71
votes
7 answers

How to validate latitude and longitude

I have two UITextFields which users can enter in a latitude and longitude, these co-ordinates are then used to create a pin on an MKMapView. I want find a way to validate whether the values they enter are actual GPS co-ordinates or just a load of…
user843337
66
votes
3 answers

MKMapView: Instead of Annotation Pin, a custom view

I want to display an image in my MKMapView instead of little rock pin. Can someone please put some helpful code here, or tell the way how to do it? -(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id )annotation { …
turtle
  • 928
  • 1
  • 11
  • 23
47
votes
3 answers

MKMapView MKPointAnnotation tap event

I have a list of annotations (MKPointAnnotation). I have a UIViewController which is for the whole view, MKMapView implementing Controller, which I thought is useful for detecting the users interaction with the map, my own MKPointAnnotation…
Ravi Vooda
  • 5,216
  • 5
  • 19
  • 25
40
votes
8 answers

How do I remove all annotations from MKMapView except the user location annotation?

I use removeAnnotations to remove my annotations from mapView but same it remove user location ann. How can I prevent this, or how to get user ann back to view? NSArray *annotationsOnMap = mapView.annotations; [mapView…
Pavel Kaljunen
  • 1,291
  • 2
  • 26
  • 53
35
votes
3 answers

MapKit not showing custom Annotation pin image on iOS9

My code worked fine from iOS 7 to 8. With the update yesterday the custom images on my pins were replaced by the standard pin image. Any suggestions? My code: extension ViewController: MKMapViewDelegate { func mapView(mapView: MKMapView,…
Felix Weber
  • 518
  • 1
  • 4
  • 8
30
votes
2 answers

How to create addressDictionary for MKPlacemark?

placemark = [[MKPlacemark alloc]initWithCoordinate:storedCoordinate addressDictionary:addressDict]; I tried to create dictionary to use for code above, but nothing works :( NSDictionary *addressDict = [[NSDictionary alloc]…
Shmidt
  • 16,436
  • 18
  • 88
  • 136
28
votes
7 answers

Detect Tap on CalloutBubble in MKAnnotationView

Im working with MKMapView and MKAnnotationView. I have an annotation in the map. When the users tap on it, the callOut Bubble is displayed. When the annotation is tapped again ( and the callOut Bubble is visible ) i need to change to another…
Alejandro González
  • 638
  • 1
  • 8
  • 17
27
votes
2 answers

How to open call out MKAnnotationView programmatically? (iPhone, MapKit)

I want to open up the callout for an MKPinAnnotationView programmatically. Eg I drop 10 pins on the map, and want to open up the one closest to me. How would I go about doing this? Apple has specified the 'selected' parameter for MKAnnotationView's,…
Stijn
  • 858
  • 2
  • 12
  • 21
26
votes
7 answers

How to remove all annotations from MKMapView without removing the blue dot?

I would like to remove all annotations from my mapview without the blue dot of my position. When I call: [mapView removeAnnotations:mapView.annotations]; all annotations are removed. In which way can I check (like a for loop on all the…
Mat
  • 7,613
  • 4
  • 40
  • 56
25
votes
7 answers

iOS : Swift - How to add pinpoint to map on touch and get detailed address of that location?

I want to add annotation on touch of iOS map and fetch the detailed address (Placemark) of respective location. How I can achieve this in Swift? Thanks in advance.
SRK
  • 744
  • 3
  • 11
  • 23
25
votes
1 answer

Animate MapKit annotation coordinate change in Swift?

When using MapKit in iOS 8 in Swift, how do I make it possible to animate a change in the map position of a custom annotation? I am saying this: UIView.animateWithDuration(0.25) { var loc = ann.coordinate loc.latitude = loc.latitude +…
matt
  • 515,959
  • 87
  • 875
  • 1,141
24
votes
3 answers

Swift - Add MKAnnotationView To MKMapView

I'm trying to add MKAnnotationView to MKMapView but I can't do it… Can anyone help me? Here is my code: override func viewDidLoad() { super.viewDidLoad() locationManager.desiredAccuracy = kCLLocationAccuracyBest …
Bogdan Bogdanov
  • 882
  • 11
  • 36
  • 79
20
votes
1 answer

How to add more details in MKAnnotation in iOS

I want to add more details in MKAnnotation like location title, description, date, location name. So it will be four lines that are needed. But I found that only 2 parameters can be passed to MKAnnotation which are title and subtitle. How can I add…
S.P.
  • 5,427
  • 11
  • 56
  • 83
19
votes
1 answer

How to create Custom MKAnnotationView and custom annotation title and subtitle

I need to create above Annotation view on MKMapView. I am able to create the custom annotation view but on the tap of annotation the view need to be opened image with that big text, I am not able to create that one. Please provide me some links or…
Abhishek
  • 2,255
  • 1
  • 13
  • 21
18
votes
6 answers

MKMapview place pin at location (long/lat)

I have latitude and long values and I need to be able to drop a pin at this location. Can anybody provide some advice on how to go about this?
3sl
  • 295
  • 2
  • 4
  • 7
1
2 3
85 86