PDA

View Full Version : Android: Kartendarstellung mehrerer gespeicherter Routen



lexos
11.11.2014, 21:53
Hallo Skobbler Team!

Vorweg, danke für eine gutes Framework zur Offlinenavigation! Leider hab ich jedoch ein Verständnisproblem mit den berechneten Routen und deren gleichzeitiger Darstellung.

Ich versuche 3 Routen gleichzeitig darzustellen:

Auto schnell
Auto kürzeste Route
Zu Fuß


Wenn ich es richtig verstanden habe, so ist eine gemeinsame Routenberechnung für diese 3 unterschiedlichen Navigationsarten nicht möglich. Wenn ich nun versuche die Routenberechnung ohne löschen der Route in der Karte durchzuführen, so werden die alten Routen dennoch überschrieben und nicht dargestellt. Versuche ich diese Routen zu speichern und danach wieder zu laden, so seh ich auch nur die Letzte.

Meine Frage nun: Ist das überhaupt möglich?

Danke für die Unterstützung!

dandronic
12.11.2014, 11:41
The scenario you are describing won't be possible by default, but there is a workaround:

- Calculate the 3 routes
- For each route get the route points via getExtendedRoutePointsForRoute (http://developer.skobbler.com/docs/android/2.3.0/com/skobbler/ngx/routing/SKRouteManager.html#getExtendedRoutePointsForRoute (int))
- Now you can draw the route points on the map as 3 SKPolylines - use different colours for each polyline so that you can visually differentiate the routes
- Additionally, you can save and load the calculated route to the cache to speed up things (i.e. once you've decided on which polyline you like, you can load that specific route from cache)

Let me know if this works for your scenario.

lexos
12.11.2014, 19:07
Hello dandronic, thanks for your support.

Unfortunately this does not work, cause the getExtendedRoutePointsForRoute function does not provide any SKExtendedRoutePosition objects in the list. The list is empty although a track is displayed on the map view. I also tried to calculate with or without displaying the route (setRouteExposed(true) and setRouteExposed(false)) and grabed the result in onRouteCalculationCompleted as well as in onAllRoutesCompleted.

Here is the code snipplet of what I tried:

List<SKExtendedRoutePosition> routePositions = SKRouteManager.getInstance().getExtendedRoutePoint sForRoute(navigationModes[navigationMode].id);
List<SKCoordinate> coordinates = new ArrayList<SKCoordinate>(routePositions.size());

for (SKExtendedRoutePosition position : routePositions) {
coordinates.add(new SKCoordinate(position.getLatitude(), position.getLongitude()));
}
SKPolyline polyline = new SKPolyline();
navigationModes[navigationMode].route.setNodes(coordinates); // fails cause coordinates is empty
// set polyline color
polyline.setColor(new float[] { 0.5f, 0.5f, 1f, 1f });
// set properties for the outline
polyline.setOutlineColor(new float[] { 0f, 0f, 1f, 1f });
polyline.setOutlineSize(4);
polyline.setOutlineDottedPixelsSolid(3);
polyline.setOutlineDottedPixelsSkip(3);
mapView.addPolyline(polyline);

Any further ideas?

Kind regards, Alex!

dandronic
13.11.2014, 14:51
Yes - when asking for the route calculation, make sure that you use setExtendedPointsReturned (http://developer.skobbler.com/docs/android/2.3.0/com/skobbler/ngx/routing/SKRouteSettings.html#setExtendedPointsReturned(boo lean))

// get a route object and populate it with the desired properties
SKRouteSettings route = new SKRouteSettings();
// set start and destination points
route.setStartCoordinate(new SKCoordinate(-122.397674, 37.761278));
route.setDestinationCoordinate(new SKCoordinate(-122.448270, 37.738761));
// set the number of routes to be calculated
route.setNoOfRoutes(1);
// set the route mode
route.setRouteMode(SKRouteSettings.SKROUTE_CAR_FAS TEST);
// set whether the route should be shown on the map after it's computed
route.setRouteExposed(true);
route.setExtendedPointsReturned(true);