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

256 questions
1
vote
0 answers

Is there a way to know if the MKAnnotationView was selected by the user or programmatically?

I have a map with annotations, but when I select it programmatically, the map should do one logic on centering. When the user selects it, another logic must be done to center. Is there a way to know when it is selected programmatically or by the…
1
vote
0 answers

Xcode MapKit App Project - images switch when zooming, rotating, and moving on map

We are building a mapkit iOS application where we are using custom annotations to put specific information about our school buildings on map pins. When the app and map first loads, everything works great. However, if we zoom, move, or rotate the…
Drew
  • 11
  • 1
1
vote
1 answer

SwiftUI/ MapKit - Populate a MapAnnotation Struct from MongoDB Realm/ Atlas collection

I am new to SwiftUI and Realm (using flexible sync), please excuse if it sounds like an elementary question I have location data saved in a MongoDB Atlas collection - Centre class Centre: Object, ObjectKeyIdentifiable { @Persisted var _id:…
1
vote
2 answers

Using web image as MapKit annotation (with image edit before)

I want to use web image as annotation on Apple Map. In other parts of my app I'm using SDWebImageSwiftUI, so I'd like to use SDWebImage also here. I know there is a SDWebImage plugin for MapKit, but it doesn't look like I can do some operations on…
Maksymilian Tomczyk
  • 1,100
  • 8
  • 16
1
vote
1 answer

Convert adress input in annotation on the map - SwiftUI

I am a beginner so sorry for my question. I have a map and annotations in a Datas file. Now I would like the user to be able to register an address with a form. How do I go from a normal address to a location: CLLocationCoordinate2D(latitude:…
Ryo
  • 15
  • 1
  • 4
1
vote
1 answer

Semi-transparent circle on top of map in SwiftUI

I am building an app in SwiftUI and am really running into a slight inconvenience. I am using MapKit to create a map where certain locations get a pin on them. I created a slider to zoom to a region within a certain radius. However for users it…
yourivdloo
  • 364
  • 2
  • 16
1
vote
0 answers

How to make SwiftUI MapPin clickable

I am using the new Map API in SwiftUI but am running into a problem. I would like to show names and perhaps an action button in a small popup when a pin is tapped, but can't seem to find out how to do this. XCode recommends me an onTapGesture…
Pimv_h
  • 380
  • 1
  • 3
  • 13
1
vote
0 answers

Hide and show views on UIMapKit annotation click

I want to show a storyboard View whenever a user taps on an annotation and it's subtitle is visible. My code works somewhat but isn't doing exactly what I want. Here's my code import MapKit class ViewController: UIViewController,MKMapViewDelegate…
1
vote
1 answer

MapKit annotation view labels changing position/showing in wrong annotation when dequeued

I'm adding labels just underneath my map pins to show some detail of the pin. I'm doing this by adding a UILabel as a subview of the annotationView and setting it's number of lines to 0 in order to display multiple lines on the same label. I'm…
jbeu425
  • 115
  • 7
1
vote
0 answers

Can i replace the Route between 2 destinations in Mapkit using MKOverlayRenderer to show a custom Route which show the distance like below Picture?

I want to replace the default route between 2 destinations with a custom one? All i found was to replace the route by setting a custom MKOverlayRenderer ex: https://www.ioscreator.com/tutorials/draw-route-mapkit-tutorial which explain how to…
killvak
  • 96
  • 8
1
vote
2 answers

Don't animate MKMarkerAnnotationView when selected

I would like to capture taps on an MKMarkerAnnotationView, and not animate the view when this happens. Through a delegate for my MKMapView, I can capture selection and deselection that are roughly equivalent to taps on the MKMarkerAnnotationView…
Guig
  • 9,891
  • 7
  • 64
  • 126
1
vote
1 answer

Faster recognition of single tap on MKMapView (Swift)

In my iOS app I have an instance of an MKMapView and on single tap, I want to add a marker to the map. I've added a UITapGestureRecognizer and immediately noticed that it would fire even when a user double taps to zoom (or other interactions with…
Erik Booij
  • 105
  • 10
1
vote
1 answer

Without Bridging to ObjectiveC, Can We Get the Coordinates of a Tap Solely in SwiftUI?

I have the following code: struct MyLocationMap: View { @EnvironmentObject var userData: UserData @State var annotationArray: [MyAnnotation] = [MyAnnotation(coordinates: CLLocationCoordinate2D(latitude:…
Yrb
  • 8,103
  • 2
  • 14
  • 44
1
vote
0 answers

Overlap CalloutMapAnnotation and other annotation

I have an overlapping problem in mapkit annotation. I set CalloutMapAnnotation in viewForAnnotation as delegate. I have gone through multiple answers and have even tried changing z index but that too has not worked for me. Here is an image of the…
Ruchi Makadia
  • 1,005
  • 1
  • 7
  • 20
1
vote
1 answer

MapKit: How do I get and set the collision frame rectangle of an annotation view?

MKAnnotationViews documentation says Managing Collisions Between Annotation Views var collisionMode: MKAnnotationView.CollisionMode The collision mode to use when interpreting the collision frame rectangle. enum…
Gerd Castan
  • 6,275
  • 3
  • 44
  • 89