使用当前位置的建筑物名称

时间:2019-05-31 05:04:21

标签: swift geolocation location mkreversegeocoder

我正在尝试使用CLLocationManagerDelegateMKMapViewDelegate来获取门牌号,但是没有用。通过使用这个,我得到了子地区区域和子行政通道以及子直通车费,但没有获得建筑物名称。

请帮助获取建筑物名称

我已经尝试使用CLLocationManagerDelegate方法reversegeocoder和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()
   }

预期结果:

DLf-Tower A, Jasola Distric Center,New Delhi
Actual Result:  Jasola Distric Center,New Delhi

1 个答案:

答案 0 :(得分:0)