###実現したいこと
iOS版のYmapKitを使用した地図機能において、ピンアイコンを変更する方法。
###現状
表示させたい画像をピンアイコンが保存されているディレクトリに配置して、
下記コードを記載して実行したところ、エラーは出力されず、デフォルトの赤いピンが表示されてしまいます。
特にエラーも出ていなく原因がつかめないため、質問させていただきました。
###ソースコード
class MapViewController: UIViewController,YMKMapViewDelegate { var mapView: YMKMapView? override func viewDidLoad() { super.viewDidLoad() // YMKMapViewのインスタンスを作成 mapView = YMKMapView(frame: CGRect(x: 0, y: 0, width: 320, height: 320), appid: “アプリID”) // 地図のタイプを指定 標準の地図を指定 mapView!.mapType = UInt(YMKMapTypeStandard) // YMKMapViewを追加 self.view = mapView! // YMKMapViewDelegateを登録 mapView!.delegate = self // 地図の位置と縮尺を設定 var center = CLLocationCoordinate2D.init(); center.latitude = 35.6657214; center.longitude = 139.7310058; mapView!.region = YMKCoordinateRegionMake(center, YMKCoordinateSpanMake(1, 1)); //ピン表示 let coordinate = CLLocationCoordinate2D(latitude: 35.6657214, longitude: 139.7310058) let myAnnotation = MyAnnotation(locationCoordinate: coordinate, title: "ミッドタウン", subtitle: "ミッドタウンです。") map?.addAnnotation(myAnnotation) } func mapView(mapView: YMKMapView!, viewForAnnotation annotation: YMKAnnotation!) -> YMKAnnotationView! { print("pin") if annotation is MyAnnotation { // マーカーのビューを引数のannotationを用いて作成する let pin = YMKPinAnnotationView(annotation: annotation, reuseIdentifier: "Pin") //アイコンイメージの変更 pin?.image = UIImage.init(named: "route_pin.png"); pin?.animatesDrop = true // アイコンのイメージのどこを基準点にするか設定 let centerOffset = CGPoint(x:15,y:15); pin?.centerOffset = centerOffset return pin } return nil }
###参考元
・http://developer.yahoo.co.jp/webapi/map/openlocalplatform/v1/iphonesdk/tutorial5.html
・http://qiita.com/k-yamada@github/items/1826b31bc9a55eea10be
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/03 01:55
2017/02/03 02:12
2017/02/03 04:57