2

I'm trying to create an MKCircle overlay on a map, however I would like the size of the circle on the screen to remain constant as the user zooms.

So as the user zooms in, the radius gets smaller and as the user zooms out, the radius gets larger.

I'm working in Swift 3. Is there a specific MapKit method I should be using to accomplish this? I know there is an option to use an image of a circle as an annotation, however I want to dynamically change the color of the circle.

In other words, I want the MKCircle to scale the same way an MKPolyline scales as you zoom in and out

Chris Schlitt
  • 561
  • 1
  • 4
  • 20

1 Answers1

2

So as the user zooms in, the radius gets smaller and as the user zooms out, the radius gets larger

An MKCircle would presumably be part of an overlay (MKOverlay). An overlay works by simulating drawing on the earth itself. Thus, the drawing changes with the zoom level.

So if you don't want that to happen, don't use an MKOverlay. You could, for example, just make a normal view that displays a circle and lay it in front of the map view. Or you could use an annotation instead (MKAnnotation); an annotation's image does not change size as the map is zoomed.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Ah I see now that my question was confusing. I guess I don't want the size of the size of the circle to change on zoom. Basically as the user zooms, I want the size of the circle to not change with respect to the screen. I'll try your suggestion with an additional view – Chris Schlitt Dec 23 '16 at 17:12
  • However would this view not change as the user pans the map? I would like the circle to stay at a specific point (coordinates) on the map as the user pans – Chris Schlitt Dec 23 '16 at 17:14
  • 1
    Sure, that's an issue. If you used an ordinary view, you'd have to track the user panning and move the view. That's why I suggested an annotation as an alternative approach. But the main goal of my answer was to suggest why an overlay is _not_ the way to do this, because what you are describing is not what an overlay _is_. – matt Dec 23 '16 at 17:19
  • Ah that makes sense. Thank you for the insight. I want to use an image, however I have to figure out a way to dynamically change the color then. Or, is there a MapKit method such as onZoom? – Chris Schlitt Dec 23 '16 at 23:39
  • @matt I disagree with your comment about what an overlay is not. If you add an overlay that uses `polylineRenderer.lineWidth = 3.0`, that width (on the map) **will** adjust as the map view is zoomed in and out. – David May 23 '17 at 00:33