2017-06-16 70 views
1

我想绘制mapview中给定轨道中卫星的地面轨迹。我已经拥有包含卫星的x,y,z位置以及经度和纬度数据的数据集。我只在绘图时遇到问题。如何将卫星地面轨迹绘制成Swift地图投影

+0

请检查我的答案,并让我知道如果你错过了什么 –

回答

3

您可以使用MKGeodesicPolyline。更多信息here

//Replace this with whatever you have for a source of locations 
var satellitePathLocations = [ 
    CLLocation(latitude: -73.761105, longitude: 41.017791), 
    CLLocation(latitude: -73.760701, longitude: 41.019348), 
    CLLocation(latitude: -73.757201, longitude: 41.019267), 
    CLLocation(latitude: -73.757482, longitude: 41.016375), 
    CLLocation(latitude: -73.761105, longitude: 41.017791) 
] 


var coordinates = satellitePathLocations.map({(location: CLLocation!) -> CLLocationCoordinate2D in return location.coordinate}) 

let polyline = MKGeodesicPolyline(coordinates: coordinates, count: coordinates.count) 
mapView.add(polyline) 

// On your MKMapView delegate 

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! { 
    if overlay is MKGeodesicPolyline { 
     var polylineRenderer = MKPolylineRenderer(overlay: overlay) 
     polylineRenderer.strokeColor = UIColor.blueColor() 
     polylineRenderer.lineWidth = 2 
     return polylineRenderer 
    } 

    return nil 
}