【问题标题】:xcode simulator bicycle ride or highway drive coordinates are wrong?xcode 模拟器骑自行车或高速公路驾驶坐标有误?
【发布时间】:2015-04-19 16:55:39
【问题描述】:

只是我还是这真的是一个错误,当我将模拟器位置设置为骑自行车时,纬度始终为 0 ,而经度正在更新?

当我打印出坐标时,我不断得到这样的数字:

0, 789442777752750357664707662594831481658901059219640184274.....

【问题讨论】:

  • 发布代码以及您对行为的描述将是一个更有效且可回答的问题。你在哪里记录坐标?你是如何记录它们的?等等

标签: xcode ios-simulator mapkit


【解决方案1】:

我想通了……

显然,以下方法中随着自行车或汽车行驶而更新的位置确实是错误的。我需要改用 aUserLocation 并使用其信息自己创建一个坐标,以找出正确的当前坐标。

- (void)mapView:(MKMapView *)aMapView didUpdateUserLocation:(MKUserLocation *)aUserLocation {
CLLocationCoordinate2D location;

我不知道为什么会这样,但这解决了它。

 CLLocationCoordinate2D loc;
    loc.latitude = aUserLocation.coordinate.latitude;
    loc.longitude = aUserLocation.coordinate.longitude;
    currentCoordinate = loc;

【讨论】:

  • 您是否记录了location 而没有将其设置为aUserLocation.coordinate?然后它当然会记录零值或随机值。 locationloc 是您声明的局部变量,它们不会自动连接到任何其他变量。局部变量最初包含不可预测的值(但通常为零)。但是您不需要自己“创建坐标”变量,因为它已经以aUserLocation.coordinate 的形式存在——您可以直接使用并记录它。
  • 但是,在某些情况下,即使在委托方法中,用户位置本身也可能无效(有关如何处理的建议,请参阅stackoverflow.com/questions/8394969/…)。
猜你喜欢
  • 2022-11-21
  • 1970-01-01
  • 2015-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多