0

I am trying to get House number using CLLocationManagerDelegate and MKMapViewDelegate but it did not work. By using this i am getting Sub-locality area and sub administrative thoroughfare and sub-through fare but not getting building name.

Please help how to get building name

I have already tried using CLLocationManagerDelegate method reversegeocoder and CLLocationManagerDelegate.

 CLGeocoder().reverseGeocodeLocation(location){ (placemark, error)   in
        let place = placemark?[0]

 print(placemark?[0].addressDictionary?[0])

        let subloc = place?.subLocality
        let city = place?.locality
        print("\(subloc!),\(city!),\(place?.administrativeArea)")
        print(place?.areasOfInterest?.count)
        if let subLocal = place?.subLocality, let cityCustom = place?.locality
       {
         self.locationname.text = ("\(subLocal),\(cityCustom)")
        self.locationname.text = (placemark?[0].addressDictionary?[0]) as? String
         self.address = self.locationname.text ?? ""
        print(placemark?[0].addressDictionary?[0]) as? String
        if let marks = placemark, marks.count > 0 {
            let placemark = marks[0]
            let postalAddress = placemark.addressDictionary

            if let address = postalAddress?.first {

                print("\(address)")
            }
            if let State = placemark.addressDictionary?["State"]{

                print("\(State)")
            }
            if let Street = placemark.addressDictionary?["Street"]{

                print("\(Street)")
            }
            if let Name = placemark.addressDictionary?["Name"]{

                print("\(Name)")
            }
            if let Thoroughfare = placemark.addressDictionary?["Thoroughfare"]{

                print("\(Thoroughfare)")
            }
            if let subThoroughfare = placemark.addressDictionary?["SubThoroughfare"]{

                print("\(subThoroughfare)")
            }
            if let FormattedAddressLines = placemark.addressDictionary?["FormattedAddressLines"]{

                print("\(FormattedAddressLines)")
                self.locationname.text = (FormattedAddressLines as AnyObject).componentsJoined(by: ",") as? String
                self.address = self.locationname.text ?? ""
                 self.locationname.numberOfLines = 2
                 self.locationname.sizeToFit()
                self.locationname.textAlignment = .center
            }
        }

     }
    else
     {
         self.alertbox(title1: UrlSheet.UrlName.msgTitle, message1: "Location service is disabled on your phone at the moment. Please enable the same before marking the attendance.")
      }
    self.mapviews.isUserInteractionEnabled = false
    manager.stopUpdatingLocation()
   }

Expected Result:

DLf-Tower A, Jasola Distric Center,New Delhi
Actual Result:  Jasola Distric Center,New Delhi
Kaushik Makwana
  • 1,329
  • 2
  • 14
  • 24
rachna sharma
  • 111
  • 2
  • 3
  • 13

1 Answers1

0

Visit: https://developer.apple.com/documentation/corelocation/clplacemark For All Supported Placemark by Apple

Threadripper
  • 622
  • 10
  • 15