如何在 map 上的两个点之间绘制箭头?
我尝试计算纬度和经度,但是出了点问题。

最好的问候,马克斯

这是我的代码和结果图片

        int currpoints1 = 2;
    NSLog(@"!!!!!!!!%d ",numPoints);
    while(currpoints1 < numPoints)
    {

        TrackPoint* current = nil;
        CLLocationCoordinate2D* coordsArrrow = malloc((3) * sizeof(CLLocationCoordinate2D));
        for (int i =currpoints1, j=0; i < numPoints; i=i+1, j++)
        {
            current = [cashpoints objectAtIndex:i];
            coordsArrrow[j] = current.coordinate;
            if (i % 2 !=0) {
                int Gug = 30;

                int ug;
                float bx, by, ex, ey;
                bx = coordsArrrow[0].latitude;by = coordsArrrow[0].longitude;
                ex = coordsArrrow[1].latitude;ey = coordsArrrow[1].longitude;
                float Lstr = sqrt((ex-ey)*(ex-ey)+(bx-by)*(bx-by));
                ug = [self RetGradW:(abs(coordsArrrow[1].latitude-coordsArrrow[0].latitude)) height:abs(coordsArrrow[1].longitude-coordsArrrow[0].longitude)];
                ug = ug - Gug;
                coordsArrrow[0].latitude  = ex;
                coordsArrrow[0].longitude = ey;
                coordsArrrow[1].latitude  = ex+Lstr*cos(ug*M_PI/180);
                coordsArrrow[1].longitude = ey+Lstr*sin(ug*M_PI/180);
                ug=ug+2*Gug;
                coordsArrrow[2].latitude  = ex+Lstr*cos(ug*M_PI/180);
                coordsArrrow[2].longitude = ey+Lstr*sin(ug*M_PI/180);

                MKPolyline *points = [MKPolyline polylineWithCoordinates:coordsArrrow count:3];
                points.subtitle = @"arrow";
                [map addOverlay:points];
                break;
            }
        }
        free(coordsArrrow);
        currpoints1 = currpoints1 +14;
    }

最佳答案

哦,伙计们。我改变其他方式。进行注释并在两个点之间沿方向旋转。

方法:

计算方向:

     int currpoints1 = 2;
    NSLog(@"!!!!!!!!%d ",numPoints);
    while(currpoints1 < numPoints)
    {

        TrackPoint* current = nil;
        CLLocationCoordinate2D* coordsArrrow = malloc((2) * sizeof(CLLocationCoordinate2D));
        for (int i =currpoints1, j=0; i < numPoints; i=i+1, j++)
        {
            current = [cashpoints objectAtIndex:i];
            coordsArrrow[j] = current.coordinate;
            if (i % 2 !=0) {
                DirectAnnotation *placemark=[[DirectAnnotation alloc] initWithCoordinate: coordsArrrow[0]];

                CLLocationCoordinate2D coord1 = coordsArrrow[0];
                CLLocationCoordinate2D coord2 = coordsArrrow[1];

                CLLocationDegrees deltaLong = coord2.longitude - coord1.longitude;
                CLLocationDegrees yComponent = sin(deltaLong) * cos(coord2.latitude);
                CLLocationDegrees xComponent = (cos(coord1.latitude) * sin(coord2.latitude)) - (sin(coord1.latitude) * cos(coord2.latitude) * cos(deltaLong));

                CLLocationDegrees radians = atan2(yComponent, xComponent);
                CLLocationDegrees degrees = radiansToDegrees(radians) + 360;

                self.dir =  fmod(degrees, 360);


                NSLog(@"%f,%f %f,%f",coordsArrrow[0].latitude,coordsArrrow[0].longitude,coordsArrrow[1].latitude,coordsArrrow[1].longitude);
                [self.map addAnnotation:placemark];
                break;
            }
        }
        free(coordsArrrow);
        currpoints1 = currpoints1 +14;
    }



注解:
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{


if ([annotation isKindOfClass:[DirectAnnotation class]]) {
    arrow=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"parkingloc"];
    arrow.image = [UIImage imageNamed:@"userLocationCompass.png"];


    CGAffineTransform transform = CGAffineTransformMakeRotation(degreesToRadians(dir));
    arrow.transform = transform;

    return arrow;
}else {
    return nil;
}}

但是我有一些问题
变焦前:

变焦后:

方向很困惑。

关于ios - 如何在 map 上的两个点之间绘制箭头? MapKit,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17829611/

10-11 04:26