1

地図上の 2 点間に矢印を描く方法は?
緯度と経度を計算しようとしましたが、何かがうまくいきません。

よろしく、マックス

これは私のコードと結果の写真です

        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;
    }

ここに画像の説明を入力

4

3 に答える 3

1

viewForAnnotation で矢印を正しく再利用しないため、矢印の角度が変わります。

viewForAnnotation で次のように、各矢印に一意の ID を作成するだけです。

routeAnnotationView = (MKAnnotationView *)[lmapView dequeueReusableAnnotationViewWithIdentifier:[NSString stringWithFormat:@"%f%f",annotation.coordinate.latitude, annotation.coordinate.longitude]];

                if (!routeAnnotationView)
                {
                    routeAnnotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[NSString stringWithFormat:@"%f%f",annotation.coordinate.latitude, annotation.coordinate.longitude]];
                    UIImage *image = [self rotateImage:[UIImage imageNamed:@"arrpix11.png"] onDegrees:RADIANS_TO_DEGREES(curAngle)+90];
                    routeAnnotationView.image = image;
                }
                else
                {
                    routeAnnotationView.annotation = annotation;
                }
                routeAnnotationView.canShowCallout = NO;
于 2015-02-26T23:43:15.430 に答える
0

これを使用して、マップ内の 2 つの場所の間のパスを描画します。

http://code.google.com/p/ashiphone/downloads/detail?name=MapWithRoutes.zip&can=2&q=

于 2013-07-24T09:10:37.067 に答える