如何使用Swift中的坐标打开MKMapItem?

时间:2016-04-22 13:32:48

标签: ios swift mapkit

 let geocoder = CLGeocoder()
        let sel = parkAnnotation.getLocation()
       let location = CLLocation(latitude: sel!.coordinate.latitude, longitude: sel!.coordinate.longitude)
        geocoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in

            // Place details
            var placeMark: CLPlacemark!
            placeMark = placemarks?[0]

            // Address dictionary
            print(placeMark.addressDictionary)

            // Location name
            if let locationName = placeMark.addressDictionary!["Name"] as? NSString {
                print(locationName)
            }

            // street address
            if let street = placeMark.addressDictionary!["Thoroughfare"] as? NSString {
                print(street)
            }

            // City
            if let city = placeMark.addressDictionary!["City"] as? NSString {
                print(city)
            }

            // Zip code
            if let zip = placeMark.addressDictionary!["ZIP"] as? NSString {
                print(zip)
            }

            // Country
            if let country = placeMark.addressDictionary!["Country"] as? NSString {
                print(country)
            }
        })

现在我需要显示地图。 我试图在点击地标时显示MKMapItem坐标,使用反向地理编码获取上面的实际地址。 现在我需要显示带有行驶方向的地图。

1 个答案:

答案 0 :(得分:0)

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    let location = locations.last as CLLocation

    let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)        
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

    self.map.setRegion(region, animated: true)
}