danicode
danicode

Reputation: 25

Problem with reverse geocoder and passing data between view controllers Xcode

I have a mapView in one view controller with an MKPointAnnotation. I've applied reverse Geocoder to get the street name from the coordinates and I'm trying to take that street name onto another view controller and place it into a label. But that label from the second view controller always shows the coordinates 0.0, instead of the street name.

func configureAddressNameTry() {
    let vc = ViewController()
    
    let lat = vc.annotation.coordinate.latitude
    let long = vc.annotation.coordinate.longitude

    let geocoder = CLGeocoder()
    geocoder.reverseGeocodeLocation(CLLocation(latitude: lat, longitude: long)) { (placemarks, error) in
        if let places = placemarks {
            for place in places {
                
                // This is the line that gives me the coordinates 0.0 (North Atlantic Ocean)
                self.addressNameTry.text = place.name
            }
        }
    }

I think I have all the necessary code for the user location and the information in the info.plist, so I don't know what I'm missing. I'm new to programming and I hope I'm not making a basic error.

Thank you for your replies :)

Upvotes: 0

Views: 46

Answers (0)

Related Questions