gpt4 book ai didi

ios - Swift MKCircle 覆盖

转载 作者:行者123 更新时间:2023-11-28 14:42:54 26 4
gpt4 key购买 nike

我正在尝试围绕 map 注释绘制 MKCircle。我认为到目前为止代码是正确的,但不确定为什么它不起作用。我相信我拥有它运行所需的所有代码。

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
}

最佳答案

您是否设置了 mapview 委托(delegate)?

self.mapView.delegate = self

不要忘记 MKMapViewDelegate 协议(protocol)。

class ViewController: UIViewController, MKMapViewDelegate  {
...
}

关于ios - Swift MKCircle 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50435825/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com