Skip to content

Instantly share code, notes, and snippets.

@futuretap
Last active March 28, 2023 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save futuretap/7e0c8ed67347aedde7ee8cf821419108 to your computer and use it in GitHub Desktop.
Save futuretap/7e0c8ed67347aedde7ee8cf821419108 to your computer and use it in GitHub Desktop.
/*
Maps.app uses its own custom marker annotations. Their icon is smaller (FB10143146), the title can be colored (FB9739380)
which is all pretty nice. Unfortunately, they’re not exposed as API. (Hence the feedbacks to expose them.)
Out of curiosity, I tried to hack around with MapKit to display them. Unfortunately, I didn’t succeed. Here’s what I tried:
I discovered _MKBalloonLabelMarkerView and its superclass _MKLabelMarkerView which might be the ones I’m looking for
(I might be wrong).
We can instantiate them using:
*/
let viewClass = NSClassFromString("_MKLabelMarkerView") as! MKAnnotationView.Type
let view = viewClass.init(annotation: annotation, reuseIdentifier: "marker")
view.annotation = annotation
// However, the annotation needs to respond to several methods from VKMarker/VKLabelMarker:
@objc public var calloutAnchorRect: CGRect {
CGRect(x: 0, y: 0, width: 100, height: 30)
}
@objc public var leftCalloutAccessoryView: UIView? {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
label.text = "*"
return label
}
@objc public var rightCalloutAccessoryView: UIView? {
nil
}
@objc public var detailCalloutAccessoryView: UIView? {
nil
}
@objc public var suppressCallout: Bool {
true
}
@objc public var isVisible: Bool {
true
}
@objc public var isRouteEta: Bool {
false
}
@objc public var pickedLabelBalloonBehavior: UInt8 {
0
}
// Unfortunately that's not even enough. When selected, it also calls `labelMarkerImpl` which is a (const void*).
// And so far, no annotation is even displayed on the map. At this point I gave up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment