[SWIFT] 경로는 MKMapView에 표시되지?
SWIFT경로는 MKMapView에 표시되지?
해결법
-
1.난 그냥 코드 아래를 시도 할 필요는 server.If에서 잘못된 응답을 받았습니다 그래서 실제로 소스 및 대상 변수는 .. 전무했다
난 그냥 코드 아래를 시도 할 필요는 server.If에서 잘못된 응답을 받았습니다 그래서 실제로 소스 및 대상 변수는 .. 전무했다
func addRoutesOverLayForMapView(){ var source:MKMapItem? var destination:MKMapItem? var sourcePlacemark = MKPlacemark(coordinate: pickUpDistanceLocation!.coordinate, addressDictionary: nil) source = MKMapItem(placemark: sourcePlacemark) var desitnationPlacemark = MKPlacemark(coordinate: dropOffDistanceLocation!.coordinate, addressDictionary: nil) destination = MKMapItem(placemark: desitnationPlacemark) let request:MKDirectionsRequest = MKDirectionsRequest() request.setSource(source) request.setDestination(destination) request.transportType = MKDirectionsTransportType.Walking let directions = MKDirections(request: request) directions.calculateDirectionsWithCompletionHandler ({ (response: MKDirectionsResponse?, error: NSError?) in if error == nil { self.showRoute(response!) } else{ println("trace the error \(error?.localizedDescription)") } }) } func showRoute(response:MKDirectionsResponse){ for route in response.routes as! [MKRoute]{ mapView.addOverlay(route.polyline, level: MKOverlayLevel.AboveRoads) var routeSeconds = route.expectedTravelTime let routeDistance = route.distance println("distance between two points is \(routeSeconds) and \(routeDistance)") } }
그리고이 대리자 메서드를 구현해야는지도보기 대리자를 설정하는 것을 잊지 해달라고
func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! { if overlay is MKPolyline { var polylineRenderer = MKPolylineRenderer(overlay: overlay) polylineRenderer.lineDashPattern = [14,10,6,10,4,10] polylineRenderer.strokeColor = UIColor(red: 0.012, green: 0.012, blue: 0.012, alpha: 1.00) polylineRenderer.lineWidth = 2.5 return polylineRenderer } return nil }
-
2.스위프트 2.1 :
스위프트 2.1 :
func addRoutesOverLayForMapView(){ var source:MKMapItem? var destination:MKMapItem? let Scoordinate = CLLocationCoordinate2D(latitude: passLat, longitude: passLong) var sourcePlacemark = MKPlacemark(coordinate: CLLocationCoordinate2D(latitude: passLat, longitude: passLong), addressDictionary: nil) source = MKMapItem(placemark: sourcePlacemark) let DCoordinate = CLLocationCoordinate2D(latitude: lati, longitude: longi) var desitnationPlacemark = MKPlacemark(coordinate: DCoordinate, addressDictionary: nil) destination = MKMapItem(placemark: desitnationPlacemark) let request:MKDirectionsRequest = MKDirectionsRequest() request.source = source request.destination = destination request.transportType = MKDirectionsTransportType.Walking let directions = MKDirections(request: request) directions.calculateDirectionsWithCompletionHandler ({ (response: MKDirectionsResponse?, error: NSError?) in if error == nil { self.showRoute(response!) } else{ print("some error") } }) } func showRoute(response:MKDirectionsResponse){ for route in response.routes { mapView.addOverlay(route.polyline, level: MKOverlayLevel.AboveRoads) let routeSeconds = route.expectedTravelTime let routeDistance = route.distance print("distance between two points is \(routeSeconds) and \(routeDistance)") } } func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer { let polylineRenderer = MKPolylineRenderer(overlay: overlay) if overlay is MKPolyline { polylineRenderer.lineDashPattern = [14,10,6,10,4,10] polylineRenderer.strokeColor = UIColor(red: 0.012, green: 0.012, blue: 0.012, alpha: 1.00) polylineRenderer.lineWidth = 2.5 return polylineRenderer } return polylineRenderer }
from https://stackoverflow.com/questions/30775154/route-not-showing-in-mkmapview by cc-by-sa and MIT license
'SWIFT' 카테고리의 다른 글
[SWIFT] UICollectionView는 API 작업과 매김 (0) | 2020.11.08 |
---|---|
[SWIFT] 스위프트의 오류 전달 (0) | 2020.11.08 |
[SWIFT] 일정 기간 동안 수동으로 이동 노드 (0) | 2020.11.08 |
[SWIFT] 사용자 정의로 자연스럽게 전환 애니메이션 (0) | 2020.11.08 |
[SWIFT] 스위프트 사용하는 TDD의 성능 테스트 (0) | 2020.11.08 |