0

数か月前に作成したマッピングプロジェクトがあり、タッチパラメータをメインのmapviewクラスに渡すヘルパークラスを使用しています。次の方法を使用して、通常、CGPointのxおよびy情報を地理座標に変換できます。

- (void)moveDetect:(NSSet *)touches :(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
NSLog(@"X:%f  Y:%f", touchPoint.x, touchPoint.y);

CLLocationCoordinate2D touchCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];

float lat = touchCoordinate.latitude;
float lng = touchCoordinate.longitude;
NSLog(@"Touch Coordinate: %f %f", lat, lng);}

最近、別のプロジェクトでコードを再利用しようとしましたが、変換が行われません。touchCoordinate変数を停止してステップインすると、最初は値が表示されます(latitude ={CLLocationDegrees}3.23141e-306およびlongitude={CLLocationDegrees} 5.46786e-48)が、次のコード行に到達すると、値は両方とも0になります。両方のプロジェクトをレビューしましたが、一方が機能し、もう一方が機能しない理由を理解できませんでした。私は時間を感謝し、正しい方向に私を導くことができる提案を楽しみにしています。ありがとう。

4

1 に答える 1

0

これを使って:

  - (void)moveDetect:(NSSet *)touches :(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchPoint = [touch locationInView:self.mapView]; //here locationInView it would be mapView
    NSLog(@"X:%f  Y:%f", touchPoint.x, touchPoint.y);

    CLLocationCoordinate2D touchCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
 }
于 2012-06-28T20:49:57.807 に答える