JiosDev
JiosDev

Reputation: 324

Google maps updating location

I am using API Google maps. When I click on the button, I call the method locationManager.startUpdatingLocation(). But this method monitors my location, and I need to take data (coordinates) only once. What should I use in this case?

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let userLocation :CLLocation = locations[0] as CLLocation
        
        print("user latitude = \(userLocation.coordinate.latitude)")
        print("user longitude = \(userLocation.coordinate.longitude)")
}

Upvotes: 0

Views: 27

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

Do

locationManager.stopUpdatingLocation()

also you can add once bool variable

Upvotes: 1

Related Questions