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

时间:2017-06-16 05:28:03

标签: ios swift

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

1 个答案:

答案 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
}
相关问题