0
Answered

Online Maps 3rd party integration problem

theboosted1 4 years ago updated 4 years ago 2

Good morning,

So I've gone from Uscript, to Nottorus, and now Bolt and I'm loving it so far...

I am trying to use Bolt with the online maps asset from the asset store https://www.assetstore.unity3d.com/en/?stay#!/content/13261

Specifically I need to access the google directions API but am having no luck. Here is the entire API list http://infinity-code.com/doxygen/online-maps/ and specifically the google direction API http://infinity-code.com/doxygen/online-maps/classOnlineMapsGoogleDirections.html

Ideally I'd like all of the API available but I'm not having any luck. scripts attached to game Objects in the scene (map base) reflect fine, however I cannot find any classes from the API. any help would be appreciated. 

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
Answered

Hi there!

Have you tried adding the types of the API you want to use to your Unit Options? 

You can do so from Tools > Bolt > Unit Options Wizard

If the asset comes in a separate DLL, you'll need to add that on the Assemblies page first.

thanks for the reply Lazlo,

Yes, I did add the types I want to use to unit options, I don't believe the asset comes in a DLL and no asset-specific entries were found in the assemblies option.

I added the google directions API (actually a script the dev created as an example of using google directions API, added below) via types in the unit options wizard, and some methods(?) did reflect, however I think he's using delegates which from my understanding bolt doesn't handle at the moment. Here is the script I'm trying to re-create or at least access:

/*     INFINITY CODE 2013-2017      */
/*   http://www.infinity-code.com   */
using System.Collections.Generic;
using UnityEngine;
namespace InfinityCode.OnlineMapsExamples
{
    /// <summary>
    /// Search a route between two locations and draws the route.
    /// </summary>
    [AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/FindDirectionExample")]
    public class FindDirectionExample : MonoBehaviour
    {
        private void Start()
        {
            // Begin to search a route from Los Angeles to the specified coordinates.
            OnlineMapsGoogleDirections query = OnlineMapsGoogleDirections.Find("Los Angeles",
                new Vector2(-118.178960f, 35.063995f));
            // Specifies that search results must be sent to OnFindDirectionComplete.
            query.OnComplete += OnFindDirectionComplete;
        }
        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);
        }
    }
}

In the start function, 

OnlineMapsGoogleDirections.Find

does reflect as a unit, and allows me to add parameters for origin, destination, etc. however, when I get to

 // Specifies that search results must be sent to OnFindDirectionComplete.
            query.OnComplete += OnFindDirectionComplete;

I cannot find this in a reflected unit, I'm assuming this is due to bolt not handling delegates?

Next is getting the results which I can't seem to access either (due to delegates?)

 private void OnFindDirectionComplete(string response)
        {
            // Get the resut object.
            OnlineMapsGoogleDirectionsResult result = OnlineMapsGoogleDirections.GetResult(response);


As a work around, I was thinking about modifying the above code so instead of calling direction.find in start, I would use a UI button press event, and pass exposed variables to the origin and destination via UI input fields. The user would type in their destination, (I already have their origin via GPS) press a "search" button to run the code.

I would however prefer to replicate this code 100% in bolt and modify it from there.

Forgive me as I am at my day job, I'll try to provide screenshots tonight to help clarify.