我对Objective-c很陌生。
在我的应用程序中,我试图将用户采取的路线绘制到地图上。
到目前为止,这是我仅获取用户当前位置的内容:
#import "StartCycleViewController.h"
#import "CrumbPath.h"
@interface StartCycleViewController ()
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) IBOutlet MKMapView *map;
@property (nonatomic, strong) UIView *containerView;
@end
@implementation StartCycleViewController
@synthesize cycleLocation = _cycleLocation;
@synthesize currentCycleLocation = _currentCycleLocation;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self startCycleLocation];
_containerView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.containerView];
[self.containerView addSubview:self.map];
// Do any additional setup after loading the view.
}
- (void)dealloc
{
self.locationManager.delegate = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - startCycleLocation
- (void)startCycleLocation{
if (!_cycleLocation){
_cycleLocation = [[CLLocationManager alloc]init];
_cycleLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_cycleLocation.distanceFilter = 10;
_cycleLocation.delegate = self;
}
[_cycleLocation startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
self.longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
self.latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
}
}
- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"%@",error);
if ( [error code] != kCLErrorLocationUnknown ){
[self stopLocationManager];
}
}
- (void) stopLocationManager {
[self.cycleLocation stopUpdatingLocation];
}
@end
我在网上浏览了一下,收集了我应该使用的信息MKPolyline
并给它坐标。但我只是不确定如何存储位置,然后MKPolyline
在应用程序运行时连续发送它们用于绘制点。