Reverse Geocode Location in Swift [closed]

别说谁变了你拦得住时间么 提交于 2019-11-27 19:05:23
Daij-Djan

you never reverse geocode the location but you pass in manager.location.

see: CLGeocoder().reverseGeocodeLocation(manager.location, ...

I assume that was a copy&paste mistake and that this is the issue - the code itself looks good - almost ;)

working code

    var longitude :CLLocationDegrees = -122.0312186
    var latitude :CLLocationDegrees = 37.33233141

    var location = CLLocation(latitude: latitude, longitude: longitude) //changed!!!
    println(location)

    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
            println(pm.locality)
        }
        else {
            println("Problem with the data received from geocoder")
        }
    })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!