ios - Get back to a view with the same directions that existed before -


well, guess 1 kinda big...

i'm making app in there mapkit , button. when user clicks button, he/she open new viewcontroller several options of destinations go. after confirming 1 wants go, mapkit view reopen directions specific place. this, created function on viewcontroller linked mapkit view:

func createmap(latit: double, longit: double){      //set what's going show in map     mapview.delegate = self     mapview.showsscale = true     mapview.showspointsofinterest = true     mapview.showsuserlocation = true      //request authorization user location data storage     locationmanager.requestalwaysauthorization()     locationmanager.requestwheninuseauthorization()      //if authorization given, use user location     if cllocationmanager.locationservicesenabled(){          locationmanager.delegate = self         locationmanager.desiredaccuracy = kcllocationaccuracybest         locationmanager.startupdatinglocation()      }      //set source , destination coordinates of direction recommendation     let sourcecoordinates = locationmanager.location?.coordinate     let destinationcoords = cllocationcoordinate2d(latitude: latit, longitude: longit)      //set placemarks source , destination coordinates     let sourceplacemark = mkplacemark(coordinate: sourcecoordinates!)     let destplacemark = mkplacemark(coordinate: destinationcoords)      //put placemarks on maps source , destination coordinates     let sourceitem = mkmapitem(placemark: sourceplacemark)     let destitem = mkmapitem(placemark: destplacemark)      //set direction request, source , destination request coordinates , transport type     let directionrequest = mkdirectionsrequest()     directionrequest.source = sourceitem     directionrequest.destination = destitem     directionrequest.transporttype = .automobile      //set response if sucess or error     let directions = mkdirections(request: directionrequest)     directions.calculate(completionhandler: {          response, error in         guard let response = response else {             if let error = error {                 print("something went wrong.")             }             return         }          //set format of route line          let route = response.routes[0]         self.mapview.add(route.polyline, level: .aboveroads)          //set map framing         let rekt = route.polyline.boundingmaprect         self.mapview.setregion(mkcoordinateregionformaprect(rekt), animated: true)       })  } 

and then, make function run, did this:

 override func viewdidload() {     super.viewdidload()          createmap(latit: lat, longit: long)  } 

lat , long variables declared publicly.

in other view, have button called "go map" in try make simple segue. however, there problem code: if directions place, reopen other view , press "go map", directions set disappear. don't know make them stay, can please help?

just bit more information: "go map" button linked mapkit view simple segue (i clicked, dragged , dropped mapkit view, didn't write line of code)

i think problem map vc added navigation stack viewdidload method not called again should move code viewdidload viewwill appear

override func viewwillappear(_ animated: bool) {         super.viewwillappear(true)          createmap(latit: lat, longit: long)      } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -