Advertisement
Alior

Find direction example

Jul 7th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. /*     INFINITY CODE 2013-2018      */
  2. /*   http://www.infinity-code.com   */
  3.  
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. namespace InfinityCode.OnlineMapsExamples
  8. {
  9.     /// <summary>
  10.     /// Search a route between two locations and draws the route.
  11.     /// </summary>
  12.     [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/FindDirectionExample")]
  13.     public class FindDirectionExample : MonoBehaviour
  14.     {
  15.         private void Start()
  16.         {
  17.             // Begin to search a route from Los Angeles to the specified coordinates.
  18.             OnlineMapsGoogleDirections query = OnlineMapsGoogleDirections.Find("Los Angeles",
  19.                 new Vector2(-118.178960f, 35.063995f));
  20.  
  21.             // Specifies that search results must be sent to OnFindDirectionComplete.
  22.             query.OnComplete += OnFindDirectionComplete;
  23.         }
  24.  
  25.         private void OnFindDirectionComplete(string response)
  26.         {
  27.             // Get the resut object.
  28.             OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);
  29.  
  30.             // Check that the result is not null, and the number of routes is not zero.
  31.             if (result == null || result.routes.Length == 0)
  32.             {
  33.                 Debug.Log("Find direction failed");
  34.                 Debug.Log(response);
  35.                 return;
  36.             }
  37.  
  38.             // Showing the console instructions for each step.
  39.             foreach (OnlineMapsGoogleDirectionsResult.Leg leg in result.routes[0].legs)
  40.             {
  41.                 foreach (OnlineMapsGoogleDirectionsResult.Step step in leg.steps)
  42.                 {
  43.                     Debug.Log(step.string_instructions);
  44.                 }
  45.             }
  46.  
  47.             // Create a line, on the basis of points of the route.
  48.             OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(result.routes[0].overview_polylineD, Color.green);
  49.  
  50.             // Draw the line route on the map.
  51.             OnlineMaps.instance.AddDrawingElement(route);
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement