註釋可能是實際上最好的選擇。使用可指定的座標屬性定義註記類(或使用MKPointAnnotation
)。
令人驚訝的是,該MKGeodesicPolyline
類是實物足以供應其計算通過points
財產(給MKMapPoint
S)或getCoordinates:range:
方法(給CLLocationCoordinate2D
S)來創建弧各個點。
(實際上,該屬性和方法都在MKMultiPoint
類MKPolyline
是的子類,MKGeodesicPolyline
是MKPolyline
一個子類。)
上的計時器和地圖視圖只要更新所述註釋的coordinate
屬性將自動移動註釋。
注意:對於這麼長的弧線,會有數千個點。
這裏是一個非常簡單的,原油使用points
財產例子,performSelector:withObject:afterDelay:
(更容易比getCoordinates:range:
方法使用):
//declare these ivars:
MKGeodesicPolyline *geodesic;
MKPointAnnotation *thePlane;
int planePositionIndex;
//after you add the geodesic overlay, initialize the plane:
thePlane = [[MKPointAnnotation alloc] init];
thePlane.coordinate = sanFrancisco;
thePlane.title = @"Plane";
[mapView addAnnotation:thePlane];
planePositionIndex = 0;
[self performSelector:@selector(updatePlanePosition) withObject:nil afterDelay:0.5];
-(void)updatePlanePosition
{
//this example updates the position in increments of 50...
planePositionIndex = planePositionIndex + 50;
if (planePositionIndex >= geodesic.pointCount)
{
//plane has reached end, stop moving
return;
}
MKMapPoint nextMapPoint = geodesic.points[planePositionIndex];
//convert MKMapPoint to CLLocationCoordinate2D...
CLLocationCoordinate2D nextCoord = MKCoordinateForMapPoint(nextMapPoint);
//update the plane's coordinate...
thePlane.coordinate = nextCoord;
//schedule the next update...
[self performSelector:@selector(updatePlanePosition) withObject:nil afterDelay:0.5];
}
這什麼都沒有做地圖包。你可以從這裏開始閱讀:[核心動畫編程指南](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html) – Desdenova
實際上它的確如此,動畫應該綁定到mapview,當用戶放大和縮小動畫時,應該是真實的地圖上的路徑......我想到的是一個註釋,它經常用一個定時器來改變,但它看起來雜亂無章。無論我不希望擁有與地圖本身斷開連接的動畫的頂層。 – chewy
你需要頂層,你會手動綁定到地圖上。沒有方便的方法可以在地圖工具包中使用。 – Desdenova