技术文章分类(180)

技术随笔(11)

swift经纬度翻译地址(CLGeocoder)

首先必须导入MapKit.framework库,并import <MapKit/MapKit.h>

这里是配合CLLocationManager(获取经纬度)使用,如果不知道CLLocationManager的用法,请参照我前面不远处的某篇博客有非常详细的记录了它的使用

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!){
        let thelocations:NSArray = locations as NSArray
        let location:CLLocation = thelocations.objectAtIndex(0) as CLLocation
        var geocoder:CLGeocoder = CLGeocoder()
        var placemarks:NSArray?
        var error:NSError?
        geocoder.reverseGeocodeLocation(location, completionHandler:{(placemarks,error) in
            if error == nil && placemarks.count > 0{
                var placemark:CLPlacemark = (placemarks as NSArray).objectAtIndex(0) as CLPlacemark
                var detailAddress:String = "\(placemark.name)"
                var address:String = "\(placemark.locality)\(placemark.subLocality)\(placemark.thoroughfare)"
                
            }
        })
        self.locationManager.stopUpdatingLocation()
    }

 

posted @ 2014-07-09 19:47  坤哥MartinLi  阅读(1170)  评论(0编辑  收藏  举报