4

Core Location フレームワーク デリゲート メソッドから取得した地理座標を変換して取得した CGPoints のコレクションがあります。コレクションは、開始点と終了点のセットです。

CoreLocation デリゲート メソッドから座標を取得しています

CLLocationCoordinate2D coordinate;
CLLocationDegrees latitude;
CLLocationDegrees longitude;

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *location = [locations lastObject];

latitude = location.coordinate.latitude;
longitude = location.coordinate.longitude;
}

以下のように、現在の緯度と経度をCGPointに変換しています

CGPoint startPoint = [mapView convertCoordinate:retrievedCoordinate toPointToView:self.view];
CGPoint endPoint = [mapView convertCoordinate:retrievedEndCoordinate toPointToView:self.view];

コレクションの値に基づいて UIView に線を引く必要があります。UIView に関して CGPoints を正しく調整/スケーリングするにはどうすればよいですか。UIView のフレームサイズは (0, 0, 768, 1004) です。

これは私が行ったスケーリングです

- (CGPoint)convertLatLongCoord:(CGPoint)latLong {
CGSize screenSize = [UIScreen mainScreen].applicationFrame.size;
CGFloat SCALE = MIN(screenSize.width, screenSize.height) / (2.0 * EARTH_RADIUS);
CGFloat OFFSET = MIN(screenSize.width, screenSize.height) / 2.0;

CGFloat x = EARTH_RADIUS * cos(latLong.x) * cos(latLong.y) * SCALE + OFFSET;
CGFloat y = EARTH_RADIUS * cos(latLong.x) * sin(latLong.y) * SCALE + OFFSET;

return CGPointMake(x, y);
}

どこ#define EARTH_RADIUS 6371

CGPoint への変換がどこかで間違っている可能性があるため、線の描画は正しくありません。私は何を間違っていますか。助けが必要です。

4

1 に答える 1

1

CLLocationCoordinate2D を CGPoint に変換するには、こちらの回答を参照してください - https://stackoverflow.com/a/372 ​​76779/2697425

于 2016-05-17T13:01:18.880 に答える