ios - 在 MKMapView 中的注释周围画一个圆圈
问题描述
我正在尝试围绕注释画一个圆圈以显示将被地理围栏的半径。
在我的 ViewController 上方,我有一个处理用户搜索结果的协议
protocol HandleMapSearch {
func dropPinZoomIn (placemark:MKPlacemark)
func setUpGeofencing (placemark:MKPlacemark)
func addRadiusCircle(placemark: MKPlacemark)
}
在 ViewController 类中,我有一个range
由滑块设置的 var。在我的 viewDidLoadmapView.delegate = self
和 ViewController 类中,我有我的 mapView 委托函数,它应该有助于绘制我的圆圈
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKCircle {
let circle = MKCircleRenderer(overlay: overlay)
circle.strokeColor = UIColor.red
circle.fillColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0.1)
circle.lineWidth = 1
return circle
} else {
return MKPolylineRenderer()
}
}
我的 addRadiusCircle 方法看起来像这样
func addRadiusCircle(placemark: MKPlacemark){
let circle = MKCircle(center: (placemark.location!.coordinate), radius: CLLocationDistance(range))
mapView.add(circle)
}
当我测试我的应用程序并搜索位置时,我在该位置的坐标处得到一个注释,但它周围没有圆圈。我尝试绘制圆圈的方式有问题吗?任何帮助将不胜感激。
解决方案
推荐阅读
- angular - 从某个函数中获取数据并将其用作 formModel 参数的默认值
- html - 如何调整图像数组和文本的大小以最适合父容器?
- algorithm - 基于两个变量调用两次递归函数的 Big-O
- java - Java 性能大
- r - 在问答论坛中抓取日期
- java - 用 Java 创建 MySQL 表看起来很乱
- mysql - 输出为 [object SequelizeInstance:transaction] 而不是 json 对象
- python - 使用 minidom 和 xml2xlsx 从 xml 转换为 xlsl 不起作用
- android - 连接失败时 okhttp 静默重试的问题
- azure-active-directory - AcquireTokenAsync 允许的额外查询参数是什么