Reputation: 78
In my code, I need to initialize my user Location: it works fine.
But whenever I want to change my location (by selecting an adress or sweeping on the screen) my app brings me back to my user Location.
I found a bit of an answer on that post.
But, I don't call didUpdateUserLocation()
. So I don't know what to do.
Does my app call frequently ViewDidLoad()
?
Here is my code, where I initialize my locations.
var usrLocation: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled()) {
usrLocation = CLLocationManager()
usrLocation.delegate = self
usrLocation.requestAlwaysAuthorization()
usrLocation.requestLocation()
usrLocation.startUpdatingLocation()
}
mapView.delegate = self
}
Also, I can not just delete my usrLocation.requestLocation()
function, I need to center on my user at the app launching. I thought of calling it elsewhere, but I have no idea of where ?
Upvotes: 0
Views: 60
Reputation: 414
you have implemented
usrLocation.startUpdatingLocation()
This is keep on updating location, so as soon you point to another location, it updates the user location.
Remove this line the code will work.
Upvotes: 1
Reputation: 78
So, as dan said, the problem was that I shouldn't call requestLocation()
and startUpdatingLocation().
So right now my code is like that, and it works perfectly:
var usrLocation: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled()) {
usrLocation = CLLocationManager()
usrLocation.delegate = self
usrLocation.requestAlwaysAuthorization()
usrLocation.requestLocation()
}
mapView.delegate = self
}
Upvotes: 0