Swiftアプリ開発初心者です。
iOS版のYmapKitを使用して地図機能の実装をしようとしておりますが、
Yahoo! iOSマップSDKドキュメントを確認したところ、Objective-Cで記載されており、実装するのが難しく感じております。
地図の表示はできましたが、その地図上の任意の場所にピン(アイコン)を表示させる実装ができません。
objc2swiftも使いましたが、上手くいきません。
実現したいこととしては、
"Yahoo! iOSマップSDKをSwiftで使ってみる"の地図の表示に、複数の任意の場所にアイコンを表示させるといったことをSwift3対応で実装したいと考えております。
ベースは下記の"Yahoo! iOSマップSDKをSwiftで使ってみる"を参考にしています。
・Yahoo! iOSマップSDKをSwiftで使ってみる
Yahoo! iOSマップSDKドキュメント
・アイコンを表示する
import UIKit class MyAnnotation: NSObject, YMKAnnotation { private(set) var coordinate: CLLocationCoordinate2D var annotationTitle: String? var annotationSubtitle: String? init(locationCoordinate coord: CLLocationCoordinate2D, title annTitle: String?, subtitle annSubtitle: String?) { coordinate = coord annotationTitle = annTitle annotationSubtitle = annSubtitle } func title() -> String? { return annotationTitle } func subtitle() -> String? { return annotationSubtitle } } class ViewController: UIViewController,YMKMapViewDelegate { var map: YMKMapView? override func viewDidLoad() { super.viewDidLoad() // YMKMapViewのインスタンスを作成 map = YMKMapView(frame: CGRect(x: 0, y: 0, width: 320, height: 320), appid: "アプリID") // 地図のタイプを指定 標準の地図を指定 map!.mapType = UInt(YMKMapTypeStandard) // YMKMapViewを追加 self.view = map! // YMKMapViewDelegateを登録 map!.delegate = self // 地図の位置と縮尺を設定 var center = CLLocationCoordinate2D.init(); center.latitude = 35.6657214; center.longitude = 139.7310058; map!.region = YMKCoordinateRegionMake(center, YMKCoordinateSpanMake(0.002, 0.002)); //ピン1個表示 let coordinate = CLLocationCoordinate2D(latitude: 35.6657214, longitude: 139.7310058) let myAnnotation = MyAnnotation(locationCoordinate: coordinate, title: "ミッドタウン", subtitle: "ミッドタウンです。") map?.addAnnotation(myAnnotation) }
回答1件
あなたの回答
tips
プレビュー