首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Swift MKCircle覆盖

Swift MKCircle覆盖
EN

Stack Overflow用户
提问于 2018-05-20 14:27:00
回答 1查看 580关注 0票数 0

我正试图围绕地图注释绘制一个MKCircle。我认为到目前为止代码是正确的,但不确定为什么它不起作用。我相信我有它工作所需的所有代码。

代码语言:javascript
复制
func getPlaces(){
    let uid = Auth.auth().currentUser?.uid
    Database.database().reference().child("Businesses").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
        // print("\(snap.value)")

        if let locationDict = snapshot.value as? [String:AnyObject]{

            let lat = Double(locationDict["businessLatitude"] as! String)
            let long = Double(locationDict["businessLongitude"] as! String)
            let center = CLLocationCoordinate2D(latitude: lat!, longitude: long!)
            let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

            let radius = 100.0

            self.mapView!.setRegion(region, animated: true)

            let circle = MKCircle(center: center, radius: radius)

            let annotation = MKPointAnnotation()
            annotation.coordinate = region.center
            self.mapView.addAnnotation(annotation)
            self.mapView.add(circle)
        }
    })
}

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    let circleRenderer = MKCircleRenderer(overlay: overlay)
    circleRenderer.strokeColor = UIColor.red
    circleRenderer.lineWidth = 1.0
    return circleRenderer
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-20 15:24:04

您设置了mapview委托吗?

代码语言:javascript
复制
self.mapView.delegate = self

别忘了MKMapViewDelegate协议。

代码语言:javascript
复制
class ViewController: UIViewController, MKMapViewDelegate  {
    ...
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50435825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档