Questions tagged [mapkitannotation]

MKAnnotation is the protocol that annotation objects must implement in order to be rendered on apple maps. The only absolute requirement is to provide a coordinate attribute. This is a CLLocationCoordinate2D object containing the latitude and longitude of your annotation.

The application obtains the data from a resource. This could be Core Data, a ReST call or any other suitable source. It is recommended that this be done on a background thread to not impact UI performance.

This data is then used to instantiate MKAnnotation objects. In addition to the required CLLocationCoordinate2D attribute a title can be supplied to display underneath the map pin. A subtitle will be displayed when the user selects the pin.

Annotations can be added individually or as an array to a MKMapView. The map will call its viewFor delegate when it is time to render the annotation. The application should attempt to dequeue an annotation view and if one is not available it should create a new one. This is the same paradigm used for table rows.

Finally assign the annotation to the AnnotationView. Additional options exist in MKMarkerAnnotationView to further customize e.g. changing the color of the marker pin.

Related tags:

References:

MKAnnotation

236 questions
27
votes
2 answers

Adding Pins to Map using MapKit - Swift 3.0

New coder, trying to figure out how to use MapKit. The goal is to create a map that users can add pins to using their address. However, the step I am at now, I am having trouble figuring out how to add pins to the map at all. How can I add a pin to…
roguephillips
  • 271
  • 1
  • 3
  • 4
14
votes
5 answers

iOS Swift MapKit Custom Annotation

I am having some trouble getting a custom annotation to load inside of my map view when I try to place a pin. import UIKit import MapKit import CoreLocation class MapViewController: UIViewController, MKMapViewDelegate,…
Ethan
  • 1,705
  • 1
  • 16
  • 44
12
votes
5 answers

MapKit Annotations Disappearing

I have an array of latitudes and another array of longitudes that I add to an array of type CLLocationCoordinate2D. I then use the new array to annotate multiple points on the map. Some, or most, or maybe even all of the annotations are displaying…
jvan
  • 133
  • 1
  • 9
7
votes
1 answer

How do I show MKOverlay above MKAnnotations?

I'm trying to use an MKOverlay (specifically an MKPolyline) to show a route on the map. However, I need the route to show up above my existing pins (custom MKAnnotationViews). Is there a good way to bring the MKPolyline to the front above the pins?
bplattenburg
  • 536
  • 1
  • 6
  • 32
6
votes
5 answers

Calculate distance between my location and a MapKit pin on Swift

I need your help, I'm working on an App where I have some pins (locations) and what I want is to get the distance between each one and my location. My code is the following let annotation = MKPointAnnotation() let annotationTwo =…
Daniel C.
  • 133
  • 1
  • 2
  • 10
6
votes
1 answer

Customize MapKit MKAnnotation Callout bubble to display a multiline text in objective c

In IOS I have a map with several MKAnnotation, Clicking on one of them I see the bubble with a text, but the text is too long, then it is not displayed in its entirety. I'm looking for a way to display text in a multiline TextView, or something…
5
votes
2 answers

How to register two or more custom annotation views?

I'm trying to register custom annotation views (I create them as a subclass of MKAnnotationView), but I have some trouble with that. Initially, I've tried to register only one custom annotation view for a single annotation marker using the code…
Tigran Iskandaryan
  • 1,161
  • 1
  • 9
  • 26
5
votes
2 answers

How to get Coordinates from Google Places API in ios Swift

I am using Alamofire and SwiftyJSON to auto complete Google Places. I integrated it well and good like this : Now, what I need is if I select a place from the table view, it is selected in the text field. But how can I get the respective latitude…
AAA
  • 95
  • 2
  • 8
4
votes
0 answers

iOS MapKit custom callout with image and text on top of a pin programmatically using swift

I am trying to show a custom call out on top of pin in the map. It is required that I show an image with some text on top of pin as my call out. The code I wrote produces the following output. However, my desired output looks like this: How can I…
Ali_C
  • 165
  • 1
  • 10
4
votes
2 answers

When is mapView:viewForAnnotation called in Swift?

According to this post whenever you call addAnnotation method, mapView:viewForAnnotation gets called However the following code called mapView:viewForAnnotation only once. I have several annotations, but "view called" was only printed once. I guess…
Danny Wang
  • 344
  • 7
  • 22
3
votes
1 answer

Custom Apple Map Annotations not working properly

What I'm trying to do is to display a custom annotation view on a map view (MKMapView), that is working fine in the app. The problem is when I'm switching between apps or changing between dark & light modes the custom annotation view seems to revert…
3
votes
3 answers

colored image for MKMarkerAnnotationView in MapKit

I am building an app for iOS, that allows the user to store images location based. Now I want to use the latest AnnotationView (MKMarkerAnnotationView) in iOS for this, because it provides automated clustering. My problem is, that this class needs a…
Mojo
  • 317
  • 5
  • 15
3
votes
2 answers

MKMarkerAnnotationView cluster color

I’ve been trying out the new iOS 11 MKMarkerAnnotationView, and finally clustering works like a charm. But the problem is that the clusters have the wrong color as you can see in the picture. How can I control this?
Anders Frohm
  • 311
  • 4
  • 14
3
votes
1 answer

MKMapView prevent annotations grouping

I have a MKMapView with several annotations and 3 of them are very close to each other. I used mapView.showAnnotations(mapView.annotations, animated: false) to display all annotations on the same region at launch but one of the 3 is hidden because…
Skoua
  • 2,690
  • 3
  • 37
  • 44
3
votes
1 answer

Loading map pins from firebase onto mapkit in swift for all users to be able to see

Im creating a tagging app, where a user can tag street art to a map, this information is then available for all users to see. I can upload my data to Firebase however Im struggling being able to pull this data back down to appear on the map as an…
1
2 3
15 16