Get location name from Latitude & Longitude in iOS

前端 未结 12 1067
遥遥无期
遥遥无期 2020-11-28 07:30

I want to find current location name from latitude and longitude,

Here is my code snippet I tried but my log shows null value in all the places except in place

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 07:39

    I implemented Niru's solution in Swift 3, posting here should anybody need it:

    let geocoder = CLGeocoder()
    geocoder.reverseGeocodeLocation(self.location!) { (placemarksArray, error) in
    
        if (placemarksArray?.count)! > 0 {
    
            let placemark = placemarksArray?.first
            let number = placemark!.subThoroughfare
            let bairro = placemark!.subLocality
            let street = placemark!.thoroughfare
    
            self.addressLabel.text = "\(street!), \(number!) - \(bairro!)"
        }
    }
    

提交回复
热议问题