PDA

View Full Version : Dynamically drawing route



high5fly
10.03.2016, 17:03
Hi,

I would like to ask whether you have a method to draw dynamically a route by following the movement of the user or should I create myself this logic? Also if someone has already done something like this will be appreciate any ideas and help. Later on if I create one myself will share it here.

KR,
Miro

high5fly
11.03.2016, 17:51
Here is, as I said the 1st draft of tracking your user and drawing the route.

#pragma mark - BRVCoreLocationManagerDelegate
- (void)coreLocationManager:(BRVCoreLocationManager *)locationMgr hasLocationUpdates:(NSArray *)locations error:(NSError *)error {

//self.locationManager.deviceCoord is just [locations lastObject];
CLLocationCoordinate2D deviceCoord = self.locationManager.deviceCoord;
CLLocationCoordinate2D startCoord = [[SKPositionerService sharedInstance] currentCoordinate];

CLLocation *startLocation = [[CLLocation alloc] initWithLatitude:startCoord.latitude longitude:startCoord.longitude];
CLLocation *nextLocation = [[CLLocation alloc] initWithLatitude:deviceCoord.latitude longitude:deviceCoord.longitude];
if ([self.polyline.coordinates count] == 0) {
self.polyline.coordinates = @[startLocation, nextLocation];
}
else {
startLocation = [self.polyline.coordinates lastObject];
self.polyline.coordinates = @[startLocation, nextLocation];
}
self.polylineId += 1;
self.polyline.identifier = self.polylineId;
[self.skMapView addPolyline:self.polyline];
}

- (SKPolyline *)polyline {

if (!_polyline) {
_polyline = [SKPolyline polyline];
_polyline.identifier = self.polylineId;
_polyline.borderDotsSize = 0.1;
_polyline.borderDotsSpacingSize = 0.1;
_polyline.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.5];
_polyline.lineWidth = 20;
}
return _polyline;
}

high5fly
15.03.2016, 11:07
A bit better implementation:



- (void)coreLocationManager:(BRVCoreLocationManager *)locationMgr hasLocationUpdates:(NSArray *)locations error:(NSError *)error {

self.lastLocation = [locations firstObject];
NSDate *eventDate = self.lastLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];

if (fabs(howRecent) < 10.0 && self.lastLocation.horizontalAccuracy < 20) {

if (self.polyline.identifier == 1) {

self.polyline.coordinates = @[self.firstRunLocation, self.firstRunLocation];
}
else {

if (self.polyline.identifier == 2) {
self.startLocation = self.firstRunLocation;
}
else {
self.startLocation = [self.polyline.coordinates firstObject];
}

CLLocationDistance metersApart = [self.startLocation distanceFromLocation:self.lastLocation];
if (metersApart > MINIMUM_DELTA_METERS && self.startLocation != self.lastLocation) {

self.polyline.coordinates = self.arrayOfNewLocations;
}
}
[self.skMapView clearOverlayWithID:self.polyline.identifier];
self.polylineId += 1;
self.polyline.identifier = (int)self.polylineId;
[self.skMapView addPolyline:self.polyline];
}

if (self.lastLocation) {
[self.arrayOfNewLocations addObject:self.lastLocation];
}
}

Adela_Silvia
18.04.2016, 14:55
If by "route" you are referring to "trail" then please check if this would help you obtain the desired results:
SKTrailSettings *trailSettings = [SKTrailSettings trailSettings];
trailSettings.enablePedestrianTrail = NO;
trailSettings.pedestrianTrailSmoothLevel = 1;
_mapView.settings.trailSettings = trailSettings;
_mapView.settings.displayMode = SKMapDisplayMode2D;

high5fly
18.04.2016, 15:08
I have tried the trail settings but i need also to save the route afterwards. So I kept using polyline.

Adela_Silvia
19.04.2016, 15:20
Those two options are complementary so you can use the trail setting and save the route using http://developer.skobbler.com/docs/ios/2.5.1/Classes/SKPositionsLoggingService.html

high5fly
19.04.2016, 15:36
Sounds nice, still don't need the route to be saved in file. Just an array of locations.

Adela_Silvia
19.05.2016, 13:44
You can do at the app level - you can use the notifications and save the positions as an array (at the SDK level we've created only the option to save them in a file, but you are free to do other ways)