0

MKMapview の座標をビュー内の cgpoint に変換しようとしています。

これが私がやっていることです:

    CGPoint point = [map convertCoordinate:coord toPointToView:self.view];
    NSLog(@"lat = %f, lon = %f", coord.latitude, coord.longitude);
    NSLog(@"x = %f, y = %f", point.x, point.y);

私が得ている出力は次のとおりです。

lat = 243568961.394369, lon = 165303343.177200 x = nan, y = nan

SOに関する他の質問を見てきましたが、これが正しい方法のようです。

お役に立てれば幸いです。

編集

ログに記録されている座標 (coord) が、意図した実際の座標ではないことに気付きました。

この座標を取得する方法は次のとおりです。

    CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(tileOverlay.mapRect.origin.x, tileOverlay.mapRect.origin.y);

そのため、MKTileOverlay の MKMapRect から座標を取得することに問題があると思います。

4

1 に答える 1

0

さて、問題は、MKMapPoint 値を使用して CLLocationCoordinate2D を作成しようとしたことです。明らかに、これは無効な座標を作成しました。これを修正するために私がしたことは次のとおりです。

    MKMapPoint mp = MKMapPointMake(tileOverlay.mapRect.origin.x, tileOverlay.mapRect.origin.y);

    CLLocationCoordinate2D coord = MKCoordinateForMapPoint(mp);

    CGPoint point = [map convertCoordinate:coord toPointToView:self.view];

そして、すべてが意図したとおりに機能します

于 2016-08-18T00:23:56.450 に答える