Ios 如何在Swift地图投影上绘制卫星地面轨迹

Ios 如何在Swift地图投影上绘制卫星地面轨迹,ios,swift,Ios,Swift,我试图在mapview中绘制卫星在给定轨道上的地面轨迹。我已经有了包含卫星x、y、z位置以及经纬度数据的数据集。我只在绘制它时遇到问题。您可以使用MKGeodesicPolyline进行绘制。更多信息 请检查我的答案,如果你遗漏了什么,请告诉我 //Replace this with whatever you have for a source of locations var satellitePathLocations = [ CLLocation(latitude: -73.761

我试图在mapview中绘制卫星在给定轨道上的地面轨迹。我已经有了包含卫星x、y、z位置以及经纬度数据的数据集。我只在绘制它时遇到问题。

您可以使用MKGeodesicPolyline进行绘制。更多信息


请检查我的答案,如果你遗漏了什么,请告诉我
//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
}