I have a traditional map from mapKit with a set of pins at their respective location. I am trying to keep the pins at the same place, while making the map invisible. Is there any way to do this? Thank you,
Asked
Active
Viewed 49 times
1 Answers
0
OK, I have to admit this one made me really curious! I don't know of a clean way of doing what you want, although I suspect there might be interesting hacks you can do around adding overlays.
One solution you might want to experiment with is to use viewForAnnotation()
to pull out the location of each pin annotation on the map, transform that to your view, then add custom views in its place. You can then hide the entire map (which would hide its pins), leaving your fake pins in place.
Off the top of my head, it would look something like this:
let annotations = mapView.annotations
for annotation in annotations {
if let annotationView = mapView.viewForAnnotation(annotation) {
let transformedFrame = view.convertRect(annotationView.frame, fromView: annotationView.superview)
let testView = UIView(frame: transformedFrame)
testView.backgroundColor = UIColor.redColor()
view.addSubview(testView)
}
}
You will have problems when the map view moves, though, so you might need to keep track of your fake pins and move them appropriately.

TwoStraws
- 12,862
- 3
- 57
- 71
-
Thanks a lot. However, it doesn't seem to work. Either the map still shows normally, either if I hide it , it shows a black screen. – jim Dec 13 '15 at 21:56
-
Where is the black screen coming from? Are you using `mapView.hidden = true`? You could always just remove the map view entirely once you have the locations of its pins. – TwoStraws Dec 13 '15 at 22:04
-
If I remove the map from its superView, the screen is still black. – jim Dec 13 '15 at 22:12
-
That suggests the view behind the map is black. What would you expect to happen? – TwoStraws Dec 13 '15 at 22:13
-
To have the pins (testView) displayed over it – jim Dec 13 '15 at 22:17
-
If you're seeing nothing, it's possible the pins hadn't loaded before you called that method. If you're sure the pins loaded, try using Xcode's view debugger to see where the test views are. – TwoStraws Dec 13 '15 at 22:18
-
Unfortunately none to be seen on the view debugger... I normally have four. I copy pasted your code exactly. – jim Dec 13 '15 at 22:52