MKAnnotationView tap on title - swift4

I want to customize my annotation view to show something like the image below. My questions are:
1) How can I customize the annotation view?
2) How can I make the app do something when user tap on the title? or tapped anywhere in the annotation view? if making it specific to the title is not possible!
I have added
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl)
but it does not get called!

Related

Calling mapView(_:viewFor:) when user location changes

I want to have the user location being shown as a custom image (not the blue beacon). I also want that whenever the user location changes its coordinates, this custom image is rotated accordingly to represent the user course. In order to achieve that, I implemented the code below. It is being called with annotation type userLocation when the app is started, so that the user location custom image is being shown fine. The problem is that when I simulate a change in user location coordinates, the delegate mapView(_:viewFor:) method is never called again with an annotation type userLocation, so the image is never rotated. (Note: the UIImage rotateImage(by:) is a custom method).
Is there some means to call mapView(_:viewFor:) so that I can update the image annotation for user location when user location changes? Thanks for any help.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isEqual(mapView.userLocation) {
// Annotation image for user location
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: nil)
annotationView.image = UIImage(named: "UserLocationImage.png")?.rotateImage(by: currentCourse)
return annotationView
}
}
Use CLLocationManagerDelegate
https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate
Implement this protocol in your code, and put your mapView function into its locationManager(_:didUpdateLocations:) method.

Mapkit annotation anchor point

I'm using a custom image for MapKit annotations using :
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {}
The "pin" shows with the right image now when I add a new annotation to my map, but it seems to use the horizontal and vertical centre of the image as the pin point. Is it possible to make this the bottom centre of the image? I could create a new image thats double the hight with the bottom being blank, but was hoping I could do this programmatically
Thanks

How in Swift to display details of multiple dropped pins

In Swift, I can add map annotation and display details using segue of a dropped pin when the user clicks the "i", but I am having trouble displaying details of multiple dropped pins using segue; unlike ViewTable no index is involved here. How do I do that?
Can this give you some hint?
func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!,
calloutAccessoryControlTapped control: UIControl!) {
//get the annotation ,maybe you need cast the type
// let anno = view.annotation
//performSegue here
}

Registering a touch event on an MKPointAnnotation

I want to set up a MKPointAnnotation so that when it is tapped I can call another function. Is there anyway to add a gesture recognizer or something like that?
Implement mapView(_ mapView: MKMapView!,didSelectAnnotationView view: MKAnnotationView!) in MKMapViewDelegate

Check which annotation is tapped, and use this information into a button code implementation

I have some annotations in my map. I need to slide them with a button that focus on them, one by one. I use this function to see if an annotation is tapped:
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!)
{
println("Annotation tapped \(view.annotation.title)")
}
How can i use it, in the implementation of my button function? This is my button code:
#IBAction func nextAnnotation(sender: UIButton)
{
// here i want to know which annotation is pressed, so i can move to the next.
}
I have all the annotations stored into an array. How can i check what annotation is tapped, and use this information into the button code implementation?
Thanks