Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios stopUpdateLocation()不´;工作不快_Ios_Swift_Location_Mapkit_Updating - Fatal编程技术网

Ios stopUpdateLocation()不´;工作不快

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

当我执行segue时,位置仍会在下一个VC中更新。我尝试将startUpdatingLocation()放入超级视图以外的其他函数中,但没有任何更改。你知道我能做什么吗?格吕埃·奥斯·曼海姆

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,并且有效。谢谢