Objective C:尝试初始化 CLLocation 实例时出错

发布于 2024-11-07 10:03:52 字数 575 浏览 0 评论 0原文

当它遇到以下代码时,我遇到错误(程序崩溃)

CLLocation *userLoc = [[CLLocation alloc] initWithCoordinate:locationManager.location.coordinate];

我尝试用以下代码替换参数,我也得到相同的错误

CLLocation *userLoc = [[CLLocation alloc] initWithCoordinate:mapView.userLocation.coordinate];

任何人都可以建议我在这里使用的用户当前的正确参数是什么地点?

谢谢!

堆栈跟踪:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CLLocation initWithCoordinate:]: unrecognized selector sent to instance 0x1e0620'

I am hitting an error (program crashed) when it hits the following code

CLLocation *userLoc = [[CLLocation alloc] initWithCoordinate:locationManager.location.coordinate];

I tried to replace the argument with the following and I get the same error as well

CLLocation *userLoc = [[CLLocation alloc] initWithCoordinate:mapView.userLocation.coordinate];

Can anyone advise me on what should be the correct argument to use here for the user's current location?

Thanks!

Zhen

Stacktrace:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CLLocation initWithCoordinate:]: unrecognized selector sent to instance 0x1e0620'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋心╮凉 2024-11-14 10:03:52

根据文档,< code>CLLocation 没有名为 initWithCooperative: 的初始值设定项。使用以下其中一项:

  • initWithLatitude:longitude:
  • initWithCooperative:altitude:horizo​​ntalAccuracy:verticalAccuracy:timestamp:
  • initWithCooperative:altitude:horizo​​ntalAccuracy:verticalAccuracy:course:speed:timestamp :

According to the documentation, CLLocation does not have an initializer called initWithCoordinate:. Use one of the following:

  • initWithLatitude:longitude:
  • initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:timestamp:
  • initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:speed:timestamp:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文