Circle around a point on an MKMapView

假如想象 提交于 2019-12-23 19:06:52

问题


I need to draw a circle with a specified radius around an arbitrary point (not necessarily the user's location) on an MKMapView. I would like the appearance to be similar to the circle that the Maps app uses, to show the accuracy of the user's location.

Is there a recommended way of doing this, or will I need to create a custom overlay?


回答1:


You might want to look at MKCircle and MKCircleView, which are part of the MapKit API and are designed for drawing circles on an MKMapView. I don't think there's an easy way to duplicate the animated "zeroing in" effect like the user location circle does, but you should be able to use these classes to show a fixed degree of accuracy around a given coordinate.




回答2:


You could use MKAnnoations, if you want to tie it to a map location, but you'll still need to provide the view (viewForAnnotation, or something similar -- see docs) to draw the circle.

If you need to know how to draw the circle, that's CGContextStrokeEllipseInRect() for the outline and CGContextFillElipseInRect() for the other part. If you put all that into a view, you can use UIView animations to make it "throb", like the blue map dot.

If you have more specific questions, you'll have to ask them -- the one was kind of open-ended.



来源:https://stackoverflow.com/questions/7369073/circle-around-a-point-on-an-mkmapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!