Topic: Draw custom routes

Hi,

I have found the examples of how to draw routes between certain points in the Atlas, but I can't get them working in my scene (could be that I am using the wrong settings). Is there maybe a simple way to draw your own custom routes just with some mouseclicks?

Thanks!

Re: Draw custom routes

Hello.

Here is an example of how to find a route between clicks.
I minimized the code as possible so that you can more easily understand how it works.

using UnityEngine;

public class DrawRouteOnClick:MonoBehaviour
{
    private int clickIndex = 0;
    private Vector2[] clicks = new Vector2[2];

    private void Start()
    {
        // Subscribe to click event
        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;
    }

    private void OnMapClick()
    {
        // Store coordinates of clicks (0 - start, 1 - finish)
        clicks[clickIndex] = OnlineMapsControlBase.instance.GetCoords();
        clickIndex++;

        // If count points == 2
        if (clickIndex == 2)
        {
            // Find a route and subscribe to complete event
            OnlineMapsGoogleDirections.Find(clicks[0], clicks[1]).OnComplete += OnGoogleDirectionsComplete;

            // Reset click index
            clickIndex = 0;
        }
    }

    private void OnGoogleDirectionsComplete(string response)
    {
        // Remove previous routes
        OnlineMaps.instance.RemoveAllDrawingElements();

        // Load result object from response string
        OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);

        // If something wrong, then return
        if (result == null || result.routes.Length == 0) return;

        // Create a route line
        OnlineMapsDrawingLine route = new OnlineMapsDrawingLine(result.routes[0].overview_polylineD, Color.red, 3);

        // Add a line to the map
        OnlineMaps.instance.AddDrawingElement(route);
    }
}
Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

3 (edited by Tim Reniers 2018-11-08 12:29:20)

Re: Draw custom routes

Thankyou for your answer. It is not drawing a road but it is detecting the mouse clicks. Could you maybe send me an example scene? Or what source, provider and type do you use? I feel like I am missing something, either the result turns out null or the routes length is null.

Re: Draw custom routes

Please make sure that you have Online Maps Key Manager component, and entered your Google API key.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: Draw custom routes

Is there any other way to draw roads, so without Google API?

Re: Draw custom routes

HERE Routing API:
http://infinity-code.com/atlas/online-m … ample.html

Open Route Service:
http://infinity-code.com/atlas/online-m … ample.html

If you know another good service for finding routes, please let me know.
But this service should be completely free, or have a some free quota.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!