【发布时间】:2015-08-01 16:42:23
【问题描述】:
我发现一些反向地理编码的方法比其他方法效果更好,我选择了当前的方法。
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
locationManager.stopUpdatingLocation()
if(locations.count > 0){
let location = locations[0] as! CLLocation
println(location.coordinate)
currLocation = location.coordinate
CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in
println(location)
if error != nil {
println("Reverse geocoder failed with error" + error.localizedDescription)
return
}
if placemarks.count > 0 {
let pm = placemarks[0] as! CLPlacemark
self.lbutton.text="\(pm.locality)"
}
else {
println("Problem with the data received from geocoder")
}
})
} else {
alert("Cannot fetch your location")
}
}
确实像魅力一样工作(但是有时更新位置需要几分钟,但这是公平的),但是,我很好奇它是否可以精确定位城镇,而不仅仅是整个州?例如,它会说 Bushwick 而不仅仅是 New York?
我知道最近(ish)反向地理编码获取数据的方式发生了变化,但我想我会问一些更精通该主题的人。
【问题讨论】:
标签: ios swift geolocation geocoding