Tôi muốn vẽ polyline trong ứng dụng Swift của mình.Làm thế nào để sử dụng MKPolylineView trong Swift
đang Swift
class MapViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var theMapView: MKMapView
override func viewDidLoad() {
super.viewDidLoad()
setMapView()
}
func setMapView() {
//theMapView.zoomEnabled = false
//theMapView.scrollEnabled = false
theMapView.rotateEnabled = false
//
var lat: CLLocationDegrees = 37.586601
var lng: CLLocationDegrees = 127.009381
//
var latDelta: CLLocationDegrees = 0.008
var lngDelta: CLLocationDegrees = 0.008
var theSpan: MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lngDelta)
var initLocation: CLLocationCoordinate2D = CLLocationCoordinate2DMake(lat, lng)
var theRegion: MKCoordinateRegion = MKCoordinateRegionMake(initLocation, theSpan)
self.theMapView.setRegion(theRegion, animated: true)
var locations = [CLLocation(latitude: 37.582691, longitude: 127.011186), CLLocation(latitude: 37.586112,longitude: 127.011047), CLLocation(latitude: 37.588212, longitude: 127.010438)]
var coordinates = locations.map({(location: CLLocation) -> CLLocationCoordinate2D in return location.coordinate})
var polyline = MKPolyline(coordinates: &coordinates, count: locations.count)
var myPolylineView : MKPolylineView
/* error */
myPolylineView.polyline = polyline // #1
myPolylineView.strokeColor = UIColor.blueColor() // #2
myPolylineView.lineWidth = 5; // #3
self.theMapView.addOverlay(myPolylineView) // #4
/* ----- */
}
}
Lỗi:
// #1 <br>
Cannot assign to 'polyline' in 'myPolylineView' <br>
// #2 <br>
'strokeColor' is unvailable: APIs deprecated as iOS 7 and earlier are unavailable in Swift <br>
// #3 <br>
'lineWidth' is unvailable: APIs deprecated as iOS 7 and earlier are unavailable in Swift <br>
// #4 <br>
Missing argument for parameter 'level' in call <br>
tôi không thể tìm ra một giải pháp cho việc này.
tôi đã làm chính xác này nhưng rendererForOverlay giao thức không được gọi .... –
@VanDuTran, đảm bảo những điều sau đây: 1) Cửa sổ xem bản đồ được kết nối, 2) Giao diện bản đồ được kết nối/đặt, 3) phương thức rendererForOverlay được viết đúng chính tả. Nếu vẫn không được gọi, hãy hỏi một câu hỏi mới với các chi tiết của bạn. – Anna
Đó là vì geojson của tôi có một số tọa độ kỳ lạ: "tọa độ": [[294636.0501,5039009.536], [294572.3566,5039049.88]] –