How to populate SKRouteSettings.alternativeRoutesModes array in Skobbler - ios

When I search for a route and have alternative routes option checked, skobbler will draw all alternative routes on the map and even start the navigation on the best one, if needed.
But I want to have all those alternative routes stored in an array and leave it to user to select which one he would use.
In the documentation I have noticed an array called alternativeRoutesModes.
But I don't know how exactly and when to populate it.
For a start, this is how I start making a route settings:
_route = [[SKRouteSettings alloc]init];
_route.startCoordinate = CLLocationCoordinate2DMake(43.209877, -108.966310);
_route.destinationCoordinate = _endTravelpoint.coordinate;
_route.shouldBeRendered = YES;
_route.routeMode = SKRouteCarFastest;
_route.numberOfRoutes = 5;
[[SKRoutingService sharedInstance] calculateRoute:_route];
Now, what exactly should I do with alternativeRoutesModes. Should I declare it before I call calculateRoute?
In the documentation it says:
Route calculation modes for alternative routes, an array of SKRouteAlternativeSettings objects. If nil, default alternatives will be generated.
Also, when I calculate route, only accessible objects from delegate methods are:
(void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation*)routeInformation
(void)routingServiceDidFailRouteCalculation:(SKRoutingService *)routingService
(void)routingServiceDidCalculateAllRoutes:(SKRoutingService *)routingService
All of this methods have SKRoutingService objects, and not SKRouteService object, from which I could pull out desired array.
Can I get an example of how to populate SKRouteSettings.alternativeRoutesModes with alternative route objects?

You can check the AlternativeRoutesViewController class in the demo project, it contains the same implementation as to what you're looking for.
The alternativeRoutesModes property can be used for advanced route configuration.
e.g. If you want to calculate 3 different type of routes(1 for pedestrian, 1 for bike, 1 for car)

Related

How to access map keys through index? Dart

dartques = {'Color':[], 'Fruits':[], 'Hobbies':[]};
How to access the values using index in map?
I need to access only key or value using index.
Just like we do in list
=>list[1]
you can get it like this
var element = dartques.values.elementAt(0);
also for Dart 2.7+ you can write extension function
extension GetByKeyIndex on Map {
elementAt(int index) => this.values.elementAt(index);
}
var element = dartques.elementAt(1);
For accessing the values by index, there are two approaches:
Get Key by index and value using the key:
final key = dartques.keys.elementAt(index);
final value = dartques[key];
Get value by index:
final value = dartques.values.elementAt(index);
You may choose the approach based on how and what data are stored on the map.
For example if your map consists of data in which there are duplicate values, I would recommend using the first approach as it allows you to get key at the index first and then the value so you can know if the value is the wanted one or not.
But if you do not care about duplication and only want to find a value based on Index then you should use the second approach, as it gives you the value directly.
Note: As per this Answer By Genchi Genbutsu, you can also use Extension methods for your convenience.
Important:
Since the default implementation for Map in dart is LinkedHashmap you are in great luck. Otherwise Generic Map is known for not maintaining order in many programming languages.
If this was asked for any other language for which the default was HashMap, it might have been impossible to answer.
You can convert it to two lists using keys and values methods:
var ques = {'Color':['a'], 'Fruits':['b'], 'Hobbies':['c']};
List keys = ques.keys.toList();
List values = ques.values.toList();
print (keys);
print (values);
The output:
[Color, Fruits, Hobbies]
[[a], [b], [c]]
So you can access it normally by using keys[0], for example.

Sending a parameter (or get the key) with inAppSettingsKit when initialising custom controller

I'm trying to initialise a custom viewcontroller and send a parameter with it but can't figure it out.
To sketch an idea:
I want to have different settings per sport (walking, running, ...) and save those in core data on the custom viewcontroller.
To know to which sport the settings belong to I need to know what sport the user tapped to get to that screen. I was thinking about doing this by sending a parameter, using a custom init for each sport or by getting the key. All of which I can't figure out.
I've looked into this issue and tried to do it like this: (item 4)
But that doesn't work, according to the IASK docs I think I also need to specify a file, but what file?
The selector must have two arguments: an NSString argument for the file name in the Settings bundle and the IASKSpecifier.
I've tried setting a File field and tried different values but without success.
I'm seriously lost here, if it's possible to get the key of the item that initialised the controller ("running" for item 4 for example) that would also be good.
I've tried so many different things I'm losing my mind, I'm obviously doing something very wrong but I have no idea what it is.
You don't need to specify an IASKSpecifier key in your Settings.plist. The way this works is you implement
SettingsPerSportViewController.m:
- (id) myinit:(NSString*)file specifier:(IASKSpecifier*)specifier {
if ((self = [super init])) {
// setup your VC
if ([specifier.key isEqualToString:#"tennis"]) {
// custom stuff for tennis
}
}
return self;
}
However, this means you build the settings view controllers for your sports on your own and don't use IASK for that.
If all sports share the same settings and you want to use IASK to generate the settings view controller, you could implement a custom settings storage and use the same Sport.plist for all sports. Your custom settings storage could then load from and save directly to Core Data. A sport property would then route the load and save operations to the right Core Data context or table.
At the root level you could have a simple static view controller that sets up and pushes an IASKAppSettingsViewController for each sport with the settingsStore property set to your custom storage subclass and the sport property set according to the selected sport.

Sitecore 8 MVC Glass Query Datasource

It seems like query datasources (ex: query:...) are not supported in Sitecore 8 MVC while using glass. I want to make a relative path so that branch templates will point to the correct datasource when created. Is there a way to do this with Sitecore's query builder? I saw the custom query option where a path can be specified but couldn't seem to get anything going. I think I might add a pipeline processor before the model gets bound by glass to change a datasource that starts with query: into a resolved path and pass that along the pipeline arguments.
You can add a datasource query to a Sublayout or Rendering Datasource Layout field. You will need to add a new Processor to the getRenderingDatasource Pipeline. I myself have used this on Branch Templates to make relative paths to the correct datasource.
Your query:. needs to be defined in the Datasource Location of the sublayout/rendering and make use of ancestor-or-self to make relative paths and traverse the tree to find the parent item holding the datasources.
query:.ancestor-or-self:: *[##templatename = 'home']/*[##templatename = 'storage']/*[##templatename = 'articles']
The processor will need to use the GetRenderingDatasourceArgs. These arguements will provide you pretty much everything you need. Essentially you will need to get the query:. you wrote in the Datasource Locations.
args.RenderingItem["Datasource Location"];
Replace the beginning of the query with the Context Item path (so that its relative) and then make a call to get the items;
private IEnumerable<Item> GetDatasourceLocationsFromQuery(string query)
{
string queryPath = query.Replace("query:.", args.ContextItemPath);
return args.ContextDatabase.SelectItem(queryPath);
}
This will then return the matching item that is the parent of the datasources.

Showing individual points in SChartLineSeries

Using ShinobiChart's SChartLineSeries chart type, I'm trying to enable the display of individual points with a circle (as in this example from ShinobiControls' user guide). Currently, the line plots without any individual points marked.
The user guide says this can indeed be done (as an option to be enabled) but without specifying how. And after scouring the documentation, I can't find this option anywhere. Anyone know if this is actually possible? Note: the SChartScatterSeries does offer this option, but I'm using the SChartLineSeries to take advantage of the built-in time series support, so need to stick with it.
You need to enable point visibility. An SChartLineSeries has a style property - which is of type SChartLineSeriesStyle. This is a subclass of SChartScatterSeriesStyle, so you have access to a pointStyle property. You just need to set your pointStyle to show points:
- (SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(int)index
{
SChartLineSeries *series = [SChartLineSeries new];
series.style.pointStyle.showPoints = YES;
return series;
}
You can then control the appearance of the points using the properties available on this style. For more information check out the following classes in the API documentation:
http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiCharts/2.3.0/Premium/Normal/Classes/SChartPointStyle.html
http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiCharts/2.3.0/Premium/Normal/Classes/SChartBasePointStyle.html
Hope that helps :)

Get NSManagedObject attribute validation regular expression

In my data model, some of the attributes have regular expressions used for data validation. There are places in my code that I would like to use those same regular expressions.
In the interest of keeping my common regular expressions in one place, I was hoping either to set these regexes in code or to retrieve them from the data model in code.
Is there a way to do this?
I want to access the Reg. Ex. property, shown below, in code.
From a NSEntityDescription you can get its attributes with the method attributesByName. Then you can use the NSPropertyDescription methods validationPredicates and setValidationPredicates:withValidationWarnings:. I assume that a predicate is created under the hood when you set the validation regex in your datamodel file...
I am not completely sure about this, but I think you can only set these values when you are creating your core data model, not once you have your core data stack set up. Is that what you want to do?
Absolutely. Everything you do in the model editor can be done or modified in code by manipulating your NSManagedObjectModel object.
Locate where the model is retrieved in your core data stack setup (maybe in your app delegate). Before returning the model, modify it in code, using constants you can #define in a central include file.
Read all about the object model's API here. More precisely, you set the model's entities after modifying an entity description, by changing the validationPredicates of one of its attributes.
I marked e1985's answer as accepted, since that's the answer that led me here. Here's the code I used to get the predicate. It's in a category for NSEntityDescription.
- (NSPredicate*)getValidationPredicateForAttribute:(NSString*)attributeName
{
NSAttributeDescription* emailAttribute = [self.attributesByName objectForKey:attributeName];
NSArray* validationPredicates = [emailAttribute validationPredicates];
if(validationPredicates.count > 0)
{
return [validationPredicates objectAtIndex:0];
}
return nil;
}

Resources