1
我想繪製mapview中給定軌道中衛星的地面軌跡。我已經擁有包含衛星的x,y,z位置以及經度和緯度數據的數據集。我只在繪圖時遇到問題。如何將衛星地面軌跡繪製成Swift地圖投影
我想繪製mapview中給定軌道中衛星的地面軌跡。我已經擁有包含衛星的x,y,z位置以及經度和緯度數據的數據集。我只在繪圖時遇到問題。如何將衛星地面軌跡繪製成Swift地圖投影
您可以使用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
}
請檢查我的答案,並讓我知道如果你錯過了什麼 –