我正在尝试在mapview的给定轨道上绘制卫星的地面轨迹。我已经有了包含卫星的x,y,z位置以及经度和纬度数据的数据集。我只有一个绘图问题。
最佳答案
您可以为此使用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
}
关于ios - 如何在Swift中将卫星地面轨迹绘制到 map 投影上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44581445/