Annotation Title in MapKit is not visible anymore - annotations

I uploaded an App to the AppStore on Monday. Everything worked fine. Since Thursday the Title of added Annotation is not visible anymore.
The App has an array of some Point of Interests. Each has a title and the coordinates. The PoI are showing and i can filter them for the title.
But the title is not visible.

I just fix it by adding the following function. Unfortunately it shows the title only by tabbing the pin.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard annotation is MKPointAnnotation else { return nil }
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
}

Related

How to change markerTintColor of specific annotationView in swift4

I created a property list for location details, title, subtitle ,type and coordinates. What I am trying to do is change the annotationView color according to the type of the location.In my code the compiler move directly to else statement. Could someone explain how can I solve this?
func readRecordFromPlist(){
//read record from plist code
}
func mapView(_ MapView: MKMapView, viewFor annotation: MKAnnotation) ->
MKAnnotationView? {
let obj = userNSObj()
if obj.type == "Type1" {
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .blue
return view
}else{
let view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "pin")
view.markerTintColor = .purple
return view
}
}

Trigger NavigationLink through tap on Annotation in Mapkit

I would like to trigger a NavigationLink through a tap on a Annotation in Mapkit. I am able to set a bool, that a certain annotation was tapped, but i never was able to call a SwiftUI View through it.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
return nil
}
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
} else {
annotationView?.annotation = annotation
}
return annotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
let selectedAssistance = self.parent.assistances.first {
$0.location.location?.coordinate == view.annotation?.coordinate
}
guard selectedAssistance != nil else {
return
}
self.parent.selectedAssistance = selectedAssistance?.serverId ?? ""
self.parent.presentSheet = true
}
I made it, by calling my own MapView in a ZStack, and placed a NavLink behind it, which is active on a Binding

MapView viewForAnnotation show white pin in circle (default)

When i do not set a delegate on MKMapView but add annotations, their images come up as the following:
However if i return a MKAnnotationView like so:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation.isKind(of: MKUserLocation.self) {
return nil
}
guard annotation is MKPointAnnotation else { return nil }
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.collisionMode = .circle
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
}
Then the icons come out looking like a vertical pin:
I know i can use a custom image on the MKAnnotationView. However, i want the default one, except i want it to look like the first rather than the second, but i also want to customise the callout. How can i achieve this?
The first image belongs to an MKMarkerAnnotationView. So ask for that, instead of an MKPinAnnotationView.

Changing colour of annotation pin with Apple's new annotation pin logo

I'm trying to change the colour of my annotation pins. However, I am wanting it to change the colour of the new Apple annotation logo. Instead, when the colours change, the new logo (as shown below) converts to the old logo (as shown below).
Is there anyway to change the colour as well as keep the new annotation pin?
Here's my code:
class MyPointAnnotation : MKPointAnnotation {
var pinTintColor: UIColor?
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "myAnnotation") as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myAnnotation")
annotationView?.canShowCallout = true
} else {
annotationView?.annotation = annotation
}
if annotation is MKUserLocation {
return nil
}
if let annotation = annotation as? MyPointAnnotation {
annotationView?.pinTintColor = annotation.pinTintColor
}
return annotationView
}
self.map.delegate = self
/// in view did load
Old pin:
New pin:
any input would be greatly appreciated!
Use MKMarkerAnnotationView instead of MKPinAnnotationView.
if annotationView == nil {
annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "myAnnotation")
annotationView?.canShowCallout = true
} else {
annotationView?.annotation = annotation
}
MKMarkerAnnotationView uses markerTintColor rather than pinTintColor.
However, this only works on iOS 11.
The new icon is only present in iOS 11.

Button on Annotation is not appearing

I have a problem with my app. In fact, when I am running my code in a separate app it is working. xCode is not showing me any errors and everything works fine but I can't see a detail button in my Annotations on MapKit. Is there a problem deeper in xCode?
That is my code:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "Education"
if annotation is Education {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
let btn = UIButton(type: .detailDisclosure)
annotationView!.rightCalloutAccessoryView = btn
} else {
annotationView!.annotation = annotation
}
return annotationView
}
return nil
}
It looks like this on my app - no detail button on the right side of annotation.
you have to set the delegate for your mapView. I usually do it in the viewDidLoad of the ViewController the mapView is in.
mapView.delgate = self
is the code you need to add.