我试图将 MKCircle 添加到地图注释中。稍后它将用于检测该区域的用户并签入(如果您有任何提示如何稍后开始,我将不胜感激)。现在这是我的代码,但我收到一个错误:
Cannot convert value of type 'CLLocationCoordinate2D.Type' to expected argument type 'CLLocationCoordinate2D'
这是我的代码,我还需要添加其他内容吗?:
import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate{
let locationManager = CLLocationManager()
struct Szczyt {
var name: String
var describtion: String
var lattitude: CLLocationDegrees
var longtitude: CLLocationDegrees
}
@IBOutlet weak var mapView: MKMapView!
@IBAction func mapTypeSegmentSelected(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
mapView.mapType = .standard
case 1:
mapView.mapType = .satellite
default:
mapView.mapType = .hybrid
}
}
**let circle = MKCircle(center: CLLocationCoordinate2D, radius: 100)** //Cannot convert value of type 'CLLocationCoordinate2D.Type' to expected argument type 'CLLocationCoordinate2D'
let szczyty = [Szczyt(name: "one", describtion: "describtion one", lattitude: 50.333061725039226, longtitude: 16.708595782487315),
Szczyt(name: "Two", describtion: "Describtion two", lattitude: 50.444874478583854, longtitude: 20.896341184611302),
Szczyt(name: "Three", describtion: "Describiton three", lattitude: 50.555134079897516, longtitude: 15.884675411850157)]
override func viewDidLoad() {
super.viewDidLoad()
checkLocationServices()
findSthOnTheMap(szczyty)
mapView.delegate = self
}
func checkLocationServices() {
if CLLocationManager.locationServicesEnabled() {
checkLocationAuthorization()
} else {
}
}
func checkLocationAuthorization() {
switch CLLocationManager.authorizationStatus() {
case .authorizedWhenInUse:
mapView.showsUserLocation = true
case .denied:
break
case .notDetermined:
locationManager.requestWhenInUseAuthorization()
mapView.showsUserLocation = true
case .restricted:
break
case .authorizedAlways:
break
}
}
func findSthOnTheMap(_ szczyty: [Szczyt]) {
for szczyt in szczyty {
let annotations = MKPointAnnotation()
annotations.title = szczyt.name
annotations.subtitle = szczyt.opis
annotations.coordinate = CLLocationCoordinate2D(latitude:
szczyt.lattitude, longitude: szczyt.longtitude)
mapView.addAnnotation(annotations)
mapView.addOverlay(circle)
}
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else { return nil }
let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker")
switch annotation.title!! {
case "one":
annotationView.markerTintColor = UIColor(red: 0.86, green: 0.99, blue: 0.79, alpha: 1.00)
annotationView.glyphImage = UIImage(named: "example")
case "two":
annotationView.markerTintColor = UIColor(red: 0.80, green: 0.98, blue: 0.73, alpha: 1.00)
annotationView.glyphImage = UIImage(named: "example")
case "three":
annotationView.markerTintColor = UIColor(red: 0.73, green: 0.98, blue: 0.68, alpha: 1.00)
annotationView.glyphImage = UIImage(named: "example")
default:
annotationView.markerTintColor = UIColor.green
annotationView.glyphImage = UIImage(named: "example")
}
return annotationView
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let circleRenderer = MKCircleRenderer(overlay: overlay)
circleRenderer.strokeColor = UIColor.red
circleRenderer.lineWidth = 1.0
return circleRenderer
}
}