【问题标题】:Convert CLLocation or CLLocationCoordinate2D to CGPoint将 CLLocation 或 CLLocationCoordinate2D 转换为 CGPoint
【发布时间】:2023-03-31 03:44:02
【问题描述】:

如何将CLLocationCLLocationCoordinate2D 转换为CGPoint。 我见过

CGPoint point = [mapView convertCoordinate:myCoordinates toPointToView:self.view];

但在我的情况下,我不需要使用 mapView。我尝试了谷歌搜索,但没有发现任何有用的信息。

编辑: 我需要将地理坐标转换为 iPad 的屏幕坐标,如Convert decimal latitude/longitude coordinates to iPad screen coordinates。 我正在尝试根据转换后的坐标值绘制线/路径。

有没有直接的方法,或者我需要写一个算法来做同样的事情。

【问题讨论】:

  • 如果你不需要使用mapView那你为什么需要将坐标转换为CGPoint呢?
  • 除了使用地图视图之外别无他法。
  • 我从- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 获得当前坐标。需要根据视图绘制路径。这里没有地图。
  • 我不确定,没有 MapView 是否可以得到它..? .但我会给出一些想法,但这应该是 STUPID idea - 加载 Mapview 并隐藏它并使用您提到的方法获取 CGPoint ...

标签: iphone ios cllocation cgpoint


【解决方案1】:
CGPoint myPoint = CGPointMake(coordinate.longitude, coordinate.latitude);

注意轴是交换的。但是除非你给出一个你想要转换坐标的坐标系,否则你的问题是没有意义的。

【讨论】:

  • 我需要将地理坐标转换为 iPad 的屏幕坐标,如stackoverflow.com/questions/16124171/…。我正在尝试根据转换后的坐标值绘制线/路径。
  • 找到所有坐标的边界框,然后对屏幕边界进行归一化(例如从所有坐标中减去纬度和经度的最小值,除以最大值,再乘以屏幕大小)。
  • 所以上面的转换不符合我的要求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-23
  • 2011-01-20
  • 2015-07-04
  • 2015-01-08
  • 2011-05-12
相关资源
最近更新 更多