Ios stopUpdateLocation()不´;工作不快
当我执行segue时,位置仍会在下一个VC中更新。我尝试将startUpdatingLocation()放入超级视图以外的其他函数中,但没有任何更改。你知道我能做什么吗?格吕埃·奥斯·曼海姆Ios stopUpdateLocation()不´;工作不快,ios,swift,location,mapkit,updating,Ios,Swift,Location,Mapkit,Updating,当我执行segue时,位置仍会在下一个VC中更新。我尝试将startUpdatingLocation()放入超级视图以外的其他函数中,但没有任何更改。你知道我能做什么吗?格吕埃·奥斯·曼海姆 import UIKit import MapKit import CoreLocation class uploadPrepare: UIViewController, UITextViewDelegate, CLLocationManagerDelegate { @IBOutlet weak
import UIKit
import MapKit
import CoreLocation
class uploadPrepare: UIViewController, UITextViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var weiterButton: UIButton!
let locationPrepare = CLLocationManager()
var regionPrepare: MKCoordinateRegion!
override func viewDidLoad() {
super.viewDidLoad()
locationPrepare.delegate = self
locationPrepare.desiredAccuracy = kCLLocationAccuracyBest
locationPrepare.requestWhenInUseAuthorization()
locationPrepare.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func weiterButtonTapped(_ sender: UIButton){
self.locationPrepare.stopUpdatingLocation()
self.performSegue(withIdentifier: "goToMapCheck", sender: self)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locationPrepare = locations[0]
let myLocationPrepare:CLLocationCoordinate2D = CLLocationCoordinate2DMake(locationPrepare.coordinate.latitude,locationPrepare.coordinate.longitude)
let span: MKCoordinateSpan = MKCoordinateSpanMake(0.0005,0.0005)
regionPrepare = MKCoordinateRegionMake(myLocationPrepare,span)
print("\(locationPrepare.coordinate.latitude)")
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
let uploadInterfaceGoing = segue.destination as! mapCheck
uploadInterfaceGoing.regionReceived = regionPrepare
}
}
实际上,在调用stopUpdateLocation()函数后,CLLocationManager仍会多次回调。最新的位置是最准确的。如果您想立即停止调用
didUpdateLocations
,只需在StopUpdateLocation.hmm之后设置self.locationPrepare.delegate=nil
,它仍然会将位置i put sender更新为Any,并且有效。谢天谢地,在调用StopUpdateLocation()函数后,CLLocationManager仍然会回调多次。最新的位置是最准确的。如果您想立即停止调用didUpdateLocations
,只需在StopUpdateLocation.hmm之后设置self.locationPrepare.delegate=nil
,它仍然会将位置i put sender更新为Any,并且有效。谢谢