Построение маршрута пользователя по карте с использованием MKPolyline
м совершенно новый для 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
для построения точек, непрерывно, пока приложение работает.