mkmapview - Swift 2.0 locationManager refreshes view but wont stay still once the view has loaded -


i'm working on app shows annotations within 30 mile radius. can part work. , on loading, zooms down current location. can zoom in/out, within few seconds if not zooms original region view.

i've scoured internet , site solutions, none have been adequate. code below not include annotations replicate problem having.

one suggestion found use locationmanager.requestlocation instead of .startupdatinglocations makes crash.

import mapkit import uikit import corelocation import foundation  class viewcontroller: uiviewcontroller, mkmapviewdelegate,         cllocationmanagerdelegate{  @iboutlet weak var mapview: mkmapview! var locationmanager = cllocationmanager() override func viewdidload() {     super.viewdidload()      locationmanager = cllocationmanager()     locationmanager.delegate = self     locationmanager.requestwheninuseauthorization()     locationmanager.startupdatinglocation()  }  func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) {     let userloction: cllocation = locations[0]     let latitude = userloction.coordinate.latitude     let longitude = userloction.coordinate.longitude     let latdelta: cllocationdegrees = 0.05     let londelta: cllocationdegrees = 0.05     let span:mkcoordinatespan = mkcoordinatespanmake(latdelta, londelta)     let location: cllocationcoordinate2d = cllocationcoordinate2dmake(latitude, longitude)     let region: mkcoordinateregion = mkcoordinateregionmake(location, span)     self.mapview.setregion(region, animated: true)     self.mapview.showsuserlocation = true } 

}

every time location changes didupdatelocations called, if distance @ least specifed distancefilter. since haven't set this, default of kcldistancefilternone. means every slight change cause function called, , code resets region setregion.

you use distancefilter reset region if location changes substantially, and/or detect user has zoomed screen, , use current 'span' rather resetting (0.05, 0.05).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -