Пример #1
0
        private void OnFindDirectionComplete(string response)
        {
            // Get the resut object.
            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            // Check that the result is not null, and the number of routes is not zero.
            if (result == null || result.routes.Length == 0)
            {
                Debug.Log("Find direction failed");
                Debug.Log(response);
                return;
            }

            // Showing the console instructions for each step.
            foreach (OnlineMapsGoogleDirectionsResult.Leg leg in result.routes[0].legs)
            {
                foreach (OnlineMapsGoogleDirectionsResult.Step step in leg.steps)
                {
                    Debug.Log(step.string_instructions);
                }
            }

            // Create a line, on the basis of points of the route.
            OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(result.routes[0].overview_polylineD, Color.green);

            // Draw the line route on the map.
            OnlineMaps.instance.AddDrawingElement(route);
        }
Пример #2
0
        private void OnComplete(string response)
        {
            Debug.Log("OnComplete");

            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            if (result == null || result.routes.Length == 0)
            {
                Debug.Log("Something wrong");
                Debug.Log(response);
                return;
            }

            OnlineMapsGoogleDirectionsResult.Route       firstRoute = result.routes[0];
            List <OnlineMapsGoogleDirectionsResult.Step> steps      = firstRoute.legs.SelectMany(l => l.steps).ToList();

            // Create a new marker in first point.
            marker = OnlineMapsMarkerManager.CreateItem(steps[0].start_location, "Car");

            // Gets points of route.
            points = firstRoute.overview_polylineD;

            // Draw the route.
            OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(points, Color.red, 3);

            OnlineMapsDrawingElementManager.AddItem(route);

            pointIndex = 0;
        }
        /// <summary>
        /// This method is called when the response from Google Directions API is received
        /// </summary>
        /// <param name="response">Response from Google Direction API</param>
        private void OnGoogleDirectionsComplete(string response)
        {
            Debug.Log(response);

            // Try load result
            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            if (result == null || result.routes.Length == 0)
            {
                return;
            }

            // Get the first route
            OnlineMapsGoogleDirectionsResult.Route route = result.routes[0];

            // Draw route on the map
            OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingLine(route.overview_polyline, Color.red, 3));

            // Calculate the distance
            int distance = route.legs.Sum(l => l.distance.value); // meters

            // Calculate the duration
            int duration = route.legs.Sum(l => l.duration.value); // seconds

            // Log distane and duration
            Debug.Log("Distance: " + distance + " meters, or " + (distance / 1000f).ToString("F2") + " km");
            Debug.Log("Duration: " + duration + " sec, or " + (duration / 60f).ToString("F1") + " min, or " + (duration / 3600f).ToString("F1") + " hours");
        }
Пример #4
0
    private void OnRequestDone(string response)
    {
        Debug.Log(response);

        OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

        if (result == null || result.routes.Length == 0)
        {
            return;
        }

        OnlineMapsDrawingElementManager.RemoveAllItems();

        OnlineMapsGoogleDirectionsResult.Route route = result.routes[0];
        OnlineMapsDrawingElementManager.AddItem(new OnlineMapsDrawingLine(route.overview_polyline, Color.blue, 3));
    }
Пример #5
0
        private void OnRequestComplete(string response)
        {
            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

            if (result == null || result.routes.Length == 0)
            {
                Debug.Log("No result");
                return;
            }

            points = result.routes[0].overview_polylineD;
            if (route == null)
            {
                route = new OnlineMapsDrawingLine(points, Color.green, 3);
                OnlineMapsDrawingElementManager.AddItem(route);
            }
            else
            {
                route.points = points;
            }

            pointIndex = 0;
        }
    public new static OnlineMapsFindDirectionResult GetResult(string response)
    {
        OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

        return(OnlineMapsUtils.DeepCopy <OnlineMapsFindDirectionResult>(result));
    }