我正在构建一个跟踪用户位置的小型应用程序,将他们的位置数据存储在一个数组中,并在 MKOverlay 中绘制折线。
我认为我已正确设置所有内容,但我收到上述错误:在 CLLocationManager 类型的对象上找不到属性坐标
ViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate, MKOverlay> {
CLLocationManager *locationManager;
NSMutableArray *trackingPointArray;
MKMapRect routeRect;
MKPolylineView *routeLineView;
MKPolyline *routeLine;
}
- (IBAction)startFollowing:(id)sender;
- (IBAction)stopFollowing:(id)sender;
@property (nonatomic, weak) IBOutlet MKMapView *mapView;
@end
问题代码
CLLocationDegrees Latitude = currentLocation.coordinate.latitude;
CLLocationDegrees Longitude = currentLocation.coordinate.longitude;
CLLocationCoordinate2D locationCoordinates = CLLocationCoordinate2DMake(Latitude, Longitude);
我想这可能是因为我没有在我的 .h 上声明对象,但是当我添加
@property (nonatomic, weak) CLLocation *coordinate;
我收到一个新错误:属性类型 CLLocation
与继承自 MKOverlay
的类型 CLLocationCoordinate2D
不兼容
从我所看到的一切来看,这应该是可行的,但当然就目前而言,它无法构建。将不胜感激朝着正确的方向前进。
最佳答案
答案就在眼前
再往上我有:
CLLocationManager *currentLocation = [locations lastObject];
错错错!!!
我应该有:
CLLocation *currentLocation = [locations lastObject];
关于ios - 在 CLLocationManager 类型的对象上找不到属性坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31041017/