我正在使用 Storyboard构建一个 iOS 应用。我已经在我的应用中实现了谷歌地图。
我正在使用 Feed Me Starter我的应用程序中的教程代码。我遇到了一个问题,我在 func reverseGeocodeCoordinate(coordinate: CLLocationCoordinate2D) 中进入 addressLabel,如下所示:
Lagere Rd, JC Nagar, Freedom Fighters Colony, Kamala Nagar, Bengaluru, Karnataka 560086
但我只想要上面的地址作为 Kamala Nagar,这意味着我只需要区域名称,我无法做到这一点,因为我是 swift 的新手,你能帮我怎么做吗?
这是我的代码:
func reverseGeocodeCoordinate(coordinate: CLLocationCoordinate2D) {
let geocoder = GMSGeocoder()
geocoder.reverseGeocodeCoordinate(coordinate) { response , error in
//Add this line
self.addressLabel.unlock()
if let address = response?.firstResult() {
println("label657656558568===\(address)");
self.addressLabel.text=response.valueForKey ("subLocality") as? NSString;
println("label===\(self.addressLabel.text)");
let labelHeight = self.addressLabel.intrinsicContentSize().height
self.mapView.padding = UIEdgeInsets(top: self.topLayoutGuide.length, left: 0, bottom: labelHeight, right: 0)
UIView.animateWithDuration(0.25) {
self.pinImageVerticalConstraint.constant = ((labelHeight - self.topLayoutGuide.length) * 0.5)
self.view.layoutIfNeeded()
}
最佳答案
你只需要给地址标签赋值,
就这样
Self.addresslabel=[response valueforkey @"streetName"];
关于ios - 在谷歌地图 ios 中只获取区域名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27645960/