1

全て、

私は最近、cocos2d を使用して滑らかな線を描くためのこのチュートリアルに従いました。http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/

素晴らしいチュートリアルです。上のレイヤーで動作するようになりましたMapViewController。ユーザーは画面を「シングルタップ」して、検索バーを非表示にし、マップに描画できます。アイデアは、ユーザーが円または正方形などの形状 (円になることを見てみましょう) を描画し、描画された形状の中心に注釈が表示されるというものです。

現時点では、ユーザーがもう一度タップして検索バーを再呼び出しし、描画モードをキャンセルすると、この「中心」に注釈が表示されます。ただし、収集されたポイントの中心には常に望ましくないオフセットがあります。ピンが描かれた形状の中心近くに落ちたり、iPhone 画面の反対側に表示されたりすることがあります。

描画された図形のtopLeft, bottomLeft, topRight,ポイントを収集しました。次に、その rect を指定して中心点を取得します。bottomRightrectの起源も考慮に入れます。

描画されたポイントから派生した中心点を取得したらCGRect、iOS の既定の方法を使用して、画面のタッチ ポイントをマップ上の位置に変換します。

ただし、一見ランダムなオフセットがあります。私は一日中この問題について考えていましたが、解決策を見つけることができないようです.

描画した形状の中心にきれいに注釈が収まるようにしたい。提案やアドバイスをいただければ幸いです。プロジェクトとソース コード全体は、ここにあります

- (void) setMarker {
    CGPoint point = [[MapSingleton mapSingleton] getMarkerPoint];
    NSLog(@"%f,%f", point.x, point.y);

    if(point.x >= 0 && point.y >= 0) {
        //Place marker annotation
        Annotation *annotation = [[Annotation alloc] init];
        annotation.coordinate = [self convertScreenToLatLong:point];
        annotation.color = RGB(255, 0, 0);
        annotation.title = @"New Annotation";

        // Add to map
        [self.mapView addAnnotation:annotation];
    }
}

-(CLLocationCoordinate2D)convertScreenToLatLong:(CGPoint)point {
    CGPoint tapPoint = point; // the tap point on the MKMapView on the device
    CLLocationCoordinate2D coordinates = [mapView convertPoint:tapPoint toCoordinateFromView:mapView]; // _customMapView in an MKMapView instance
    NSLog(@"Tap at : %f, %f", coordinates.latitude, coordinates.longitude);
    return coordinates;
}

これはなく、これが欲しい。

4

0 に答える 0