我正在尝试围绕地图注释绘制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
}
答案 0 :(得分:1)
您是否设置了mapview委托?
self.mapView.delegate = self
不要忘记MKMapViewDelegate
协议。
class ViewController: UIViewController, MKMapViewDelegate {
...
}