Пример #1
0
        public void ShowRoute(MapPos startPos, MapPos stopPos)
        {
            Log.Debug("calculating path " + startPos + " to " + stopPos);

            if (!offlinePackageReady)
            {
                RunOnUiThread(() =>
                {
                    string message = "Offline package is not ready, using online routing";
                    Toast.MakeText(ApplicationContext, message, ToastLength.Long).Show();
                });
            }

            if (!shortestPathRunning)
            {
                shortestPathRunning = true;
                long timeStart;

                // run routing in background
                Task.Run(() =>
                {
                    timeStart          = Java.Lang.JavaSystem.CurrentTimeMillis();
                    MapPosVector poses = new MapPosVector();

                    poses.Add(startPos);
                    poses.Add(stopPos);

                    RoutingRequest request = new RoutingRequest(BaseProjection, poses);
                    RoutingResult result;

                    if (offlinePackageReady)
                    {
                        result = offlineRoutingService.CalculateRoute(request);
                    }
                    else
                    {
                        result = onlineRoutingService.CalculateRoute(request);
                    }

                    // Now update response in UI thread
                    RunOnUiThread(() =>
                    {
                        if (result == null)
                        {
                            Alert("Routing failed");
                            shortestPathRunning = false;
                            return;
                        }

                        string distance    = "The route is " + (int)(result.TotalDistance / 100) / 10f + "km";
                        string time        = "(" + result.TotalTime.ConvertFromSecondsToHours() + ")";
                        string calculation = "| Calculation: " + (Java.Lang.JavaSystem.CurrentTimeMillis() - timeStart) + " ms";

                        Alert(distance + time + calculation);

                        routeDataSource.Clear();

                        startMarker.Visible = false;

                        Line line = CreatePolyline(startMarker.Geometry.CenterPos, stopMarker.Geometry.CenterPos, result);
                        routeDataSource.Add(line);

                        // Add instruction markers
                        RoutingInstructionVector instructions = result.Instructions;

                        for (int i = 0; i < instructions.Count; i++)
                        {
                            RoutingInstruction instruction = instructions[i];
                            MapPos position = result.Points[instruction.PointIndex];
                            CreateRoutePoint(position, instruction, routeDataSource);
                        }

                        shortestPathRunning = false;
                    });
                });
            }
        }
Пример #2
0
        public void showRoute(MapPos startPos, MapPos stopPos)
        {
            Log.Debug("calculating path " + startPos + " to " + stopPos);

            if (!offlinePackageReady)
            {
                RunOnUiThread(() => {
                    Toast.MakeText(ApplicationContext, "Offline package is not ready, using online routing", ToastLength.Long).Show();
                });
            }

            if (!shortestPathRunning)
            {
                shortestPathRunning = true;
                long timeStart;

                // run routing in background
                Task.Run(() => {
                    timeStart          = Java.Lang.JavaSystem.CurrentTimeMillis();
                    MapPosVector poses = new MapPosVector();
                    poses.Add(startPos);
                    poses.Add(stopPos);
                    RoutingRequest request = new RoutingRequest(baseProjection, poses);
                    RoutingResult result;
                    if (offlinePackageReady)
                    {
                        result = offlineRoutingService.CalculateRoute(request);
                    }
                    else
                    {
                        result = onlineRoutingService.CalculateRoute(request);
                    }


                    // now update response in UI thread
                    RunOnUiThread(() => {
                        if (result == null)
                        {
                            Toast.MakeText(ApplicationContext, "Routing failed", ToastLength.Long).Show();
                            shortestPathRunning = false;
                            return;
                        }

                        String routeText = "The route is " + (int)(result.TotalDistance / 100) / 10f
                                           + "km (" + secondsToHours((int)result.TotalTime)
                                           + ") calculation: " + (Java.Lang.JavaSystem.CurrentTimeMillis() - timeStart) + " ms";
                        Log.Info(routeText);

                        Toast.MakeText(ApplicationContext, routeText, ToastLength.Long).Show();

                        routeDataSource.RemoveAll();

                        startMarker.Visible = false;

                        routeDataSource.Add(createPolyline(startMarker.Geometry
                                                           .CenterPos, stopMarker.Geometry.CenterPos, result));

                        // add instruction markers
                        RoutingInstructionVector instructions = result.Instructions;
                        for (int i = 0; i < instructions.Count; i++)
                        {
                            RoutingInstruction instruction = instructions [i];
                            // Log.d(Const.LOG_TAG, instruction.toString());
                            createRoutePoint(result.Points [instruction.PointIndex], instruction.StreetName,
                                             instruction.Time, instruction.Distance, instruction.Action, routeDataSource);
                        }

                        shortestPathRunning = false;
                    });
                });
            }
        }
        public void ShowRoute(MapPos startPos, MapPos stopPos)
        {
            Log.Debug("calculating path " + startPos + " to " + stopPos);

            if (!offlinePackageReady)
            {
                InvokeOnMainThread(() =>
                {
                    string message = "Offline package is not ready. Using online routing";
                    Alert(message);
                });
            }

            if (!shortestPathRunning)
            {
                shortestPathRunning = true;
                long timeStart;

                // run routing in background
                System.Threading.Tasks.Task.Run(delegate
                {
                    timeStart          = DateTime.Now.ToUnixTime();
                    MapPosVector poses = new MapPosVector {
                        startPos, stopPos
                    };

                    RoutingRequest request = new RoutingRequest(BaseProjection, poses);
                    RoutingResult result;

                    if (offlinePackageReady)
                    {
                        result = offlineRoutingService.CalculateRoute(request);
                    }
                    else
                    {
                        result = onlineRoutingService.CalculateRoute(request);
                    }

                    // Now update response in UI thread
                    InvokeOnMainThread(delegate
                    {
                        if (result == null)
                        {
                            Alert("Routing failed");
                            shortestPathRunning = false;
                            return;
                        }

                        routeDataSource.Clear();

                        startMarker.Visible = false;

                        Line line = CreatePolyline(startMarker.Geometry.CenterPos, stopMarker.Geometry.CenterPos, result);
                        routeDataSource.Add(line);

                        // Add instruction markers
                        RoutingInstructionVector instructions = result.Instructions;

                        for (int i = 0; i < instructions.Count; i++)
                        {
                            RoutingInstruction instruction = instructions[i];
                            MapPos position = result.Points[instruction.PointIndex];
                            CreateRoutePoint(position, instruction, routeDataSource);
                        }

                        string distance    = "The route is " + (int)(result.TotalDistance / 100) / 10f + "km";
                        string time        = " (" + result.TotalTime.ConvertFromSecondsToHours() + ") ";
                        string calculation = "| Calculation: " + (DateTime.Now.ToUnixTime() - timeStart) + " ms";

                        Alert(distance + time + calculation);

                        shortestPathRunning = false;
                    });
                });
            }
        }