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'
4

1 回答 1

3

根据文档CLLocation没有一个名为initWithCoordinate:. 使用以下方法之一:

  • initWithLatitude:longitude:
  • initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:timestamp:
  • initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:course:speed:timestamp:
于 2011-05-14T17:43:17.440 回答