/// <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");
        }
Esempio n. 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;
        }
Esempio n. 3
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));
    }