mkmapviewcllocationcoordinate2d

adding points from a CLLocationCoordinate2D array on MKMapView doesn't work


I am using the following code to add stored pin points to myMKMap on button click ;

func addPoint(){
    var count: Int = 0
    repeat {
        let pin = MKPointAnnotation()
        pin.coordinate = CLLocationCoordinate2D(mypointList[count])
        pin.title = placenames[count]
        pin.subtitle = placedetails[count]
        mymap.addAnnotation(pin)
        count += 1
    }
    while count < 3

mypointList[] is like below ;

var mypointList = [CLLocationCoordinate2D(latitude: 37.19722, longitude: 25.82189),
           CLLocationCoordinate2D(latitude: 37.20103, longitude: 25.83009),
           CLLocationCoordinate2D(latitude: 37.20092, longitude: 25.81781),
           CLLocationCoordinate2D(latitude: 37.19989, longitude: 2259.82449)]
var placenames: [String] = ["sample place 1", "sample place 2", "sample place 3", "sample place 4"]
var placedetails: [String] = ["sample place detail 1", "sample place detail 2", "sample place detail 3", "sample place detail 4"]

but pins are not added when I run the application.

By the way, following code works when replace with the "pin.coordinate = CLLocationCoordinate2D(mypointList[count])" line in repeat loop ;

pin.coordinate = CLLocationCoordinate2D(latitude: 37.1972, longitude: 25.2744)

Is there any problem with the array ?

Thank you


Solution

  • However it sounds like a bit weird solution, I've fixed my problem with replacing the following code :

    pin.coordinate = CLLocationCoordinate2D(latitude: mypointList[count].latitude as! CLLocationDegrees, longitude: mypointList[count].longitude as! CLLocationDegrees)
    

    It displays the pins correctly now.