以下代码将在两点之间创建一个漂亮的弧.想象一下,动画视觉将代表沿着这条弧线飞行的飞机.
-(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];}解决方法 实际上,注释可能是最佳选择.使用可指定的坐标属性(或使用MKPointAnnotation)定义注记类.
令人惊讶的是,MKGeodesicpolyline类足以提供它计算的各个点,通过points属性(给出MKMapPoints)或getCoordinates:range:方法(给出CLLocationCoordinate2Ds)来创建弧.
(实际上,该属性和方法在MKMultiPoint类中,MKpolyline是MKpolyline的子类,而MKGeodesicpolyline是MKpolyline的子类.)
只需在计时器上更新注释的坐标属性,地图视图就会自动移动注释.
注意:对于这么长的弧,会有数千个点.
这是一个非常简单粗略的例子,使用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];}总结
以上是内存溢出为你收集整理的ios – 在MapKit中沿弧线为可视元素设置动画全部内容,希望文章能够帮你解决ios – 在MapKit中沿弧线为可视元素设置动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)