Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

get address from latitude and longitude in swift

func getAddressFromLatLon(pdblLatitude: String, withLongitude pdblLongitude: String) {
        var center : CLLocationCoordinate2D = CLLocationCoordinate2D()
        let lat: Double = Double("(pdblLatitude)")!
        //21.228124
        let lon: Double = Double("(pdblLongitude)")!
        //72.833770
        let ceo: CLGeocoder = CLGeocoder()
        center.latitude = lat
        center.longitude = lon

        let loc: CLLocation = CLLocation(latitude:center.latitude, longitude: center.longitude)


        ceo.reverseGeocodeLocation(loc, completionHandler:
            {(placemarks, error) in
                if (error != nil)
                {
                    print("reverse geodcode fail: (error!.localizedDescription)")
                }
                let pm = placemarks! as [CLPlacemark]

                if pm.count > 0 {
                    let pm = placemarks![0]
                    print(pm.country)
                    print(pm.locality)
                    print(pm.subLocality)
                    print(pm.thoroughfare)
                    print(pm.postalCode)
                    print(pm.subThoroughfare)
                    var addressString : String = ""
                    if pm.subLocality != nil {
                        addressString = addressString + pm.subLocality! + ", "
                    }
                    if pm.thoroughfare != nil {
                        addressString = addressString + pm.thoroughfare! + ", "
                    }
                    if pm.locality != nil {
                        addressString = addressString + pm.locality! + ", "
                    }
                    if pm.country != nil {
                        addressString = addressString + pm.country! + ", "
                    }
                    if pm.postalCode != nil {
                        addressString = addressString + pm.postalCode! + " "
                    }


                    print(addressString)
              }
        })

    }
Comment

PREVIOUS NEXT
Code Example
Swift :: swift reload tableviewcell at index 
Swift :: swift string concatenation 
Swift :: struct vs enum swift 
Swift :: change font of substring swift 
Swift :: swiftui 100 days 
Swift :: swift add width/height constraint to view 
Swift :: loop backwards swift 
Swift :: swift arrays 
Swift :: how to low case string swift 
Swift :: uiview set inside padding 
Swift :: concatenate string swift 
Swift :: simple alert swifti 
Swift :: Prime number or not program in swift basic programs 
Swift :: case insensitive multiple word search swift 
Swift :: ios UIButton change image 
Swift :: undefined symbol __swift_force_load_$swift webkit react native 
Swift :: make text autoresize swiftui 
Swift :: swift enum nib 
Swift :: value to value in sum 
Swift :: tap to delete xcode 
Swift :: Swift Change Value of a Variable 
Swift :: how to multiply numbers in array swift 
Swift :: how to darken view swiftui 
Swift :: Rules for naming Swift Variables 
Swift :: star score rating swiftui 
Swift :: image copy swift extension 
Swift :: uicolor gray 
Swift :: secure password field in textfield swift 
Swift :: enum Associated Values Swift 
Ruby :: rails include route helpers in console 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =