How to get current user coordinates in Swift (CLLocationManager)?
Hello everyone! I'm a beginner in iOS development and I'm having trouble getting the user's current location. I need to get latitude and longitude to send them to the server. I've imported CoreLocation, added keys to Info.plist (NSLocationWhenInUseUsageDescription), wrote the code, but the coordinates always come back as nil or nil. Here's my code:
```swift
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
if let location = locationManager.locati
No answers yet.
Log in to leave an answer