I need to display pins ( annotations ) on a map. Then draw polygon lines from pin to pin ( annotation to annotation )
I receive an array of Doubles that I convert to CLLocationCoordiante2D. the first lat and long values are always 0.0 so I remove those from the array because I don't want any issues there.
I map the doubles to the coordinates, and add them to the mapView
I also included a viewFor function with I thought I don't really need?
the map doesn't zoom to any location and NO pins are shown. I know I need to code that in, I will want a general radius around all the pins. Ill work on that after the pins actually show up.
Also, I don't care about names, I just want the pins to show up.
I have tried setting a single coordinate and still no pin.
The mapView delegate is correctly set in viewDidLoad()
I log the locations in debugger and they show up correct.
func createAnnotations() {
latitude.remove(at: 0)
longitude.remove(at: 0)
let coordinates = zip(latitude, longitude).map(CLLocationCoordinate2D.init)
AppLogger.logInfo("\(coordinates)")
let annotations = zip(coordinates, names)
.map { (coordinate, name) -> MKPointAnnotation in
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
annotation.title = name
return annotation
}
mapView.addAnnotations(annotations)
mapView.showAnnotations(annotations, animated: true)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard annotation is MKPointAnnotation else { return nil }
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
}
[__C.CLLocationCoordinate2D(latitude: 41.89454659591164, longitude: -87.67463844121563), __C.CLLocationCoordinate2D(latitude: 41.89424383424124, longitude: -87.67461071330482))]
The expected result is when the mapView is shown, we see the pins ( annotations ), and polygon lines connecting them from first pin to last. the draw polygon I can work on later.