swift - CLLocationCoordinate2D into one array -


i have dynamic amount of locations being plotted onto mapkit. curious on how can current latitudes , longitudes single array, being printed separate objects not plotting not map should. know problem not sure how fix it. here current code produce coordinates -

  {         let place = try mycontext.executefetchrequest(fetchrequest) as! [places]          coords in place{             let latarray = double(coords.latitude!)             let lonarray = double(coords.longitude!)             let arraytitles = coords.title!              let destination:cllocationcoordinate2d = cllocationcoordinate2dmake(latarray, lonarray)          print(destination)      } catch let error nserror {         // failure         print("fetch failed: \(error.localizeddescription)")     } 

and here print in console - output

what need print work correctly - desired output

i hope understand mean. grateful of help! thank reading.

you create array of cllocationcoordinate2ds:

var coordinatearray: [cllocationcoordinate2d] = []  if latarray.count == lonarray.count {     var = 0; < latarray.count; i++ {         let destination = cllocationcoordinate2dmake(latarray[i], lonarray[i])         coordinatearray.append(destination)     } } 

edit:

in code, neither latarray nor lonarray array. if want create array of cllocationcoordinate2ds, should add variable store locations , loop should this:

var locations: [cllocationcoordinate2d] = []  coords in place{     let lat = double(coords.latitude!)     let lon = double(coords.longitude!)     let title = coords.title!      let destination = cllocationcoordinate2dmake(lat, lon)     print(destination) // prints each location separately      if !locations.contains(destination) {         locations.append(destination)     } }  print(locations) // prints locations array  // can use locations anywhere in scope defined array. func getlocationfromarray() {     // loop through locations array:     location in locations {         print(location) // prints each location separately again     } } 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -