gpt4 book ai didi

ios - 如何在 Swift 中使用坐标打开 MKMapItem?

转载 作者:行者123 更新时间:2023-11-30 13:29:02 27 4
gpt4 key购买 nike

 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)
}
})

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

最佳答案

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)
}

关于ios - 如何在 Swift 中使用坐标打开 MKMapItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36795306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com