質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1121閲覧

Value of type '(MKMapView, MKOverlay) -> MKOverlayRenderer' has no member 'delegate'の直し方が分からない

katuobot

総合スコア6

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2020/06/03 05:54

前提・実現したいこと

エラーを治したい
地図を使ってルート検索をしたいです。

発生している問題・エラーメッセージ

Value of type '(MKMapView, MKOverlay) -> MKOverlayRenderer' has no member 'delegate'

ソースコード
import UIKit
import MapKit

class MapViewController: UIViewController {

//座標の配列 let coordinatesArray = [ ["name":"東京駅", "lat":35.68124, "lon": 139.76672], ["name":"皇居外苑", "lat":35.68026, "lon": 139.75801], ["name":"国立劇場", "lat":35.6818, "lon": 139.74326], ["name":"九段下駅", "lat":35.69555, "lon": 139.75074] ] override func viewDidLoad() { super.viewDidLoad() self.mapView.delegate = self makeMap() } func makeMap(){ //マップの表示域を設定 let coordinate = CLLocationCoordinate2DMake(coordinatesArray[0]["lat"] as! CLLocationDegrees, coordinatesArray[0]["lon"] as! CLLocationDegrees) let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) let region = MKCoordinateRegion(center: coordinate, span: span) self.mapView.setRegion(region, animated: true) var routeCoordinates: [CLLocationCoordinate2D] = [] for i in 0..<coordinatesArray.count { let annotation = MKPointAnnotation() let annotationCoordinate = CLLocationCoordinate2DMake(coordinatesArray[i]["lat"] as! CLLocationDegrees, coordinatesArray[i]["lon"] as! CLLocationDegrees) annotation.title = coordinatesArray[i]["name"] as? String //ピンの吹き出しに名前が出るように annotation.coordinate = annotationCoordinate routeCoordinates.append(annotationCoordinate) self.mapView.addAnnotation(annotation) } var myRoute: MKRoute! let directionsRequest = MKDirections.Request() var placemarks = [MKMapItem]() //routeCoordinatesの配列からMKMapItemの配列にに変換 for item in routeCoordinates{ let placemark = MKPlacemark(coordinate: item, addressDictionary: nil) placemarks.append(MKMapItem(placemark: placemark)) } directionsRequest.transportType = .walking //移動手段は徒歩 for (k, item) in placemarks.enumerated(){ if k < (placemarks.count - 1){ directionsRequest.source = item //スタート地点 directionsRequest.destination = placemarks[k + 1] //目標地点 let direction = MKDirections(request: directionsRequest) direction.calculate(completionHandler: {(response, error) in if error == nil { myRoute = response?.routes[0] self.mapView.addOverlay(myRoute.polyline, level: .aboveRoads) //mapViewに絵画 } }) } } }

}

extension MapViewController:MKMapViewDelegate {

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { if annotation is MKUserLocation { return nil } let reuseId = "pin" var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) if pinView == nil { pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) pinView?.canShowCallout = true //吹き出しで情報を表示出来るように }else{ pinView?.annotation = annotation } return pinView } //ピンを繋げている線の幅や色を調整 func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { let route: MKPolyline = overlay as! MKPolyline let routeRenderer = MKPolylineRenderer(polyline: route) routeRenderer.strokeColor = UIColor(red:1.00, green:0.35, blue:0.30, alpha:1.0) routeRenderer.lineWidth = 3.0 return routeRenderer }

}
``

試したこと

ネットで調べてみましたが当てはまりませんでした
ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

swift5
xcode11

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TsukubaDepot

2020/06/03 06:43

このコードは何か参考にして作られたものでしょうか。 ネットや書籍の記事であれば出典を提示して頂ければと思います。
guest

回答1

0

ベストアンサー

6行目に以下の記述が抜けているようです。

Swift

1 @IBOutlet weak var mapView: MKMapView!

ご存知かと思いますが、この行はInterface Builderで作成するStoryBoardと関連づける必要がありますので、お忘れなく作業するようにお願いします。

投稿2020/06/03 10:18

TsukubaDepot

総合スコア5086

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

katuobot

2020/06/03 14:49

ごめんなさい。書き忘れていました。ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問