Joe Sene Joe Sene - 1 year ago 112
Swift Question

Get users location

So I´ve been working on a task that gets the User's Location.

I worked on this code, it builds and runs nicely on the emulator.

But it does not get my current location.

Am I mssing something? If so, please help!

Here's my code:

Capture from Xcode

Answer Source

You can try changing your didUpdateLocation to this.

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let userLocation:CLLocation = locations[0] as CLLocation


        let location = CLLocationCoordinate2D(latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude)

        let span = MKCoordinateSpanMake(0.05, 0.05)

        let region = MKCoordinateRegion(center: location, span: span)

        myMap.setRegion(region, animated: true)


Hope it will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download