Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在管线/覆盖上移动注释,并沿移动方向旋转注释?_Objective C_Iphone_Mkmapview_Mkannotation_Mkpolyline - Fatal编程技术网

Objective c 如何在管线/覆盖上移动注释,并沿移动方向旋转注释?

Objective c 如何在管线/覆盖上移动注释,并沿移动方向旋转注释?,objective-c,iphone,mkmapview,mkannotation,mkpolyline,Objective C,Iphone,Mkmapview,Mkannotation,Mkpolyline,我试图沿着一条路线移动注释,如图所示 我试图通过使用MKGeodesicPolyline查找源和目标之间的坐标来移动注释。但在这种情况下,注释会沿直线移动,如图所示。 此运动的代码如下所示:- -(void)toGetRoute:(CLPlacemark*)destinationCoord { MKDirectionsRequest *directionRequest=[MKDirectionsRequest new]; MKMapItem *source=[MKMapI

我试图沿着一条路线移动注释,如图所示

我试图通过使用
MKGeodesicPolyline
查找源和目标之间的坐标来移动注释。但在这种情况下,注释会沿直线移动,如图所示。

此运动的代码如下所示:-

 -(void)toGetRoute:(CLPlacemark*)destinationCoord
{
    MKDirectionsRequest *directionRequest=[MKDirectionsRequest new];

    MKMapItem *source=[MKMapItem mapItemForCurrentLocation];
    [directionRequest setSource:source];

    CLLocationCoordinate2D destinationCoordinates=  CLLocationCoordinate2DMake(destinationCoord.location.coordinate.latitude, destinationCoord.location.coordinate.longitude);


    CLLocation *LAX = [[CLLocation alloc] initWithLatitude:37.332331
                                                 longitude:-122.031219];
    CLLocation *JFK = [[CLLocation alloc] initWithLatitude:37.365080
                                                 longitude:-121.984600];

    CLLocationCoordinate2D coordinates[2] =
    {LAX.coordinate, JFK.coordinate};


//    MKMapPoint points=MKMapPointForCoordinate(destinationCoordinates) ;
    geodesic=[MKGeodesicPolyline polylineWithCoordinates:coordinates count:2];//polylineWithPoints:&points count:2];

    NSLog(@"pointCount %lu", (unsigned long)geodesic.pointCount);
    [self.mapView addOverlay:geodesic];


    MKPlacemark *destinationPlacemark=[[MKPlacemark alloc]initWithCoordinate:destinationCoordinates addressDictionary:nil];
    MKMapItem *destination=[[MKMapItem alloc]initWithPlacemark:destinationPlacemark];
    [directionRequest setDestination:destination];


    directionRequest.requestsAlternateRoutes=YES; // to show multiple route.
    directionRequest.transportType=MKDirectionsTransportTypeAutomobile;

    MKDirections *direction=[[MKDirections alloc]initWithRequest:directionRequest];
    //calculate the actual route
    [direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse * _Nullable response, NSError * _Nullable error) {


        if (error) {
            NSLog(@"There was an error getting your directions");
            return;
        }

        NSLog(@"no of routes %lu",response.routes.count);


//        [self showMultipleRoute:response];

        currentRoute=[response.routes firstObject];
        [self plotRouteOnMap:currentRoute destinationCoordinate:destinationCoord];

        for (MKRouteStep *step in currentRoute.steps)
        {
            NSLog(@"%@", step.instructions);
        }


    }];
}
这里我们更新注释:-

-(void)updatePlanePosition:(MKAnnotationView *)view
{
    //this example updates the position in increments of 50...
    planePositionIndex = planePositionIndex + 1;

    if (planePositionIndex >= geodesic.pointCount)
    {
        //plane has reached end, stop moving
        return;
    }

    MKMapPoint nextMapPoint = geodesic.points[planePositionIndex];


    //convert MKMapPoint to CLLocationCoordinate2D...
    CLLocationCoordinate2D nextCoord = MKCoordinateForMapPoint(nextMapPoint);


    NSLog(@"nextCoord %f,%f",nextCoord.latitude,nextCoord.longitude);
    //update the plane's coordinate...
    [pntanotation setCoordinate:nextCoord];
    //    [UIView animateWithDuration:10.0f
    //                     animations:^{
    //
    //                         [view.annotation setCoordinate:nextCoord];
    //                         //                         [mapView setCenterCoordinate:CLLocationCoordinate2DMake(28.5, 77.00) animated:YES];
    //                     }completion:^(BOOL finished) {
    //                         NSLog(@"annotation animation completed");
    //                     }];

    //schedule the next update...
    [self performSelector:@selector(updatePlanePosition:) withObject:nil afterDelay:0.3];
}
但我不想直线移动注释。我想它应该沿着路线移动,并且应该沿着移动的方向旋转

请帮帮我