在MapKit中沿着圆弧创build视觉元素
我如何添加和animation一个视觉元素,沿着一个弧,我已经在mapkit内创build ?
下面的代码将在两点之间创build一个不错的弧线。 想象一下,一个animation的视觉,将代表沿着这条弧线飞行的飞机。
-(void)addArc { CLLocationCoordinate2D sanFrancisco = { 37.774929, -122.419416 }; CLLocationCoordinate2D newYork = { 40.714353, -74.005973 }; CLLocationCoordinate2D pointsArc[] = { sanFrancisco, newYork }; // MKGeodesicPolyline *geodesic; geodesic = [MKGeodesicPolyline polylineWithCoordinates:&pointsArc[0] count:2]; // [self.mapView addOverlay:geodesic]; }
实际上,注释可能是最好的select。 使用可指定的坐标属性定义注记类(或使用MKPointAnnotation
)。
令人惊讶的是, MKGeodesicPolyline
类足以提供通过points
属性(给出MKMapPoint
)或getCoordinates:range:
方法(给出CLLocationCoordinate2D
)创build圆弧的单个点。
(实际上,该属性和方法位于MKMultiPoint
类的MKMultiPoint
类中, MKPolyline
是MKGeodesicPolyline
的一个子类。)
只需更新计时器上的注释coordinate
属性,地图视图就会自动移动注释。
注意:对于这么长的弧线,会有数千个点。
这里有一个非常简单的例子,它使用了points
属性(比getCoordinates:range:
方法更容易使用)和performSelector:withObject:afterDelay:
::
//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]; }
- 如何selecttabBar项目,以模态方式显示viewController
- 在单一视图上隐藏iPhone上的状态栏?
- 我如何使用GLKit将不同的纹理应用于不同的对象?
- Xcode聊天应用程序,创builddynamic视图 – 有点失落
- UIAutomation iOS中的延迟和pushTimeout(),popTimeout()之间的区别
- 主线程中延迟的调用方法
- 内容拥抱优先级dynamic单元格大小
- iOS Swift,使用标签更新tableview CellForRow之外的UITableView自定义单元格标签
- 适用于iOS 10 XCode 8.1 Swift 3.0的NavigationBar背景图片