gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:43:04 25 4
gpt4 key购买 nike

我尝试使用CLLocationManagerDelegateMKMapViewDelegate获取门牌号,但它不起作用。通过使用这个,我得到了次区域、次行政 channel 和次直达票价,但没有得到建筑物名称。

请帮忙如何获取建筑物名称

我已经尝试使用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

最佳答案

关于swift - 使用当前位置的建筑物名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56388926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com