ios - Unable to update markers on GMaps using Swift and Parse db -


i wrote function grabs data parse db , displays markers on google maps. in viewdidload function have nstimer calls function every second. problem experience array of spotnames, spotgeopoints keeps appending , growing after each function call. also, unable remove marker in real time on map if parkingspotisempty value false.

any suggestion how make more efficient?

func displayparkingspots() {          let query:pfquery = pfquery(classname: "parkinglocations")         // query.wherekey("parkingspotisempty", equalto: true)         query.findobjectsinbackgroundwithblock { (objects:[pfobject]?, error: nserror?) -> void in             if !(error != nil) { object in objects! {                  if (object["parkingspotisempty"] as! int == 1) {                     self.spotnames.append(object["spotnames"] as! string)                     self.spotgeopoints.append(object["longitude"] as! pfgeopoint)                     self.spotlocationlatitudes.append(self.spotgeopoints.last?.latitude cllocationdegrees!)                     self.spotlocationlongitudes.append(self.spotgeopoints.last?.longitude cllocationdegrees!)                     print(self.spotnames)                     let parkingspotsposition = cllocationcoordinate2d(latitude: self.spotlocationlatitudes.last!, longitude: self.spotlocationlongitudes.last!)                     let marker = gmsmarker(position: parkingspotsposition)                     marker.title = self.spotnames.last                     //marker.icon = gmsmarker.markerimagewithcolor(uicolor.greencolor())                     marker.icon = uiimage(named: "parking-location")                     marker.tracksinfowindowchanges = true                     marker.map = self.gmapsview                 }                  }             }         }      }  override func viewdidload() {         super.viewdidload()          displayparkingspots()         gametimer = nstimer.scheduledtimerwithtimeinterval(1, target: self, selector: #selector(displayparkingspots), userinfo: nil, repeats: true)          locationmanager.delegate = self         locationmanager.requestwheninuseauthorization()          gmapsview.addobserver(self, forkeypath: "mylocation", options: nskeyvalueobservingoptions.new, context: nil)     } 


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -