アプリに位置検索バーを追加しました。
テーブルビューコントローラは、ユーザーの場所lat/longと宛先(ユーザーが検索バーに入力するアドレス)で構成されます。私の知る限り緯度/経度はplacemark.coordinate内である:destLatとdestLong:lat/long placemark.coordinate swiftを抽出する方法
placemark.coordinate = CLLocationCoordinate2D(latitude: 45.253519203737767, longitude: -66.070974382763978)
Iは、2つの変数を持っています。上記の2つの変数にplacemark.coordinateとplaceから緯度と経度を抽出する方法は?
関連コード:
// cache the pin
selectedPin = placemark
// clear existing pins
mapView.removeAnnotations(mapView.annotations)
let annotation = MKPointAnnotation()
annotation.coordinate = placemark.coordinate
annotation.title = placemark.name
if let city = placemark.locality,
let prov = placemark.administrativeArea {
annotation.subtitle = "\(city), \(prov)"
}
let destination = placemark.coordinate
print("Destination coordinates: \(destination)")
let name = placemark.name
print("Placemark Name: \(name!)")
mapView.addAnnotation(annotation)
let span = MKCoordinateSpanMake(0.05, 0.05)
let region = MKCoordinateRegionMake(placemark.coordinate, span)
mapView.setRegion(region, animated: true)
コンソール出力:
任意の助けを大幅に高く評価されるだろう。
これを見てみると、次のようになります。http://stackoverflow.com/questions/24706885/how-can-i-plot-addresses-in-swift-converting-address-to-longitude-and-latitude –