Topic: How to add my Google Developers key?

Hello,

I'm using OnlineMapsGoogleDirections.Find to find a route between two locations.
But it seems I reached the rate-limit and started to receive this message:

<?xml version="1.0" encoding="UTF-8"?>
<DirectionsResponse>
<status>OVER_QUERY_LIMIT</status>
<error_message>You have exceeded your rate-limit for this API. We recommend registering for a key at the Google Developers Console: https://console.developers.google.com/a … essage>
</DirectionsResponse>


I already have a Google Developers key but I have no idea where should I add it. can you help me with this please?


Another question please:
According to the documentation; I can pass multiple waypoints to the previous function:

"Google Direction - is a service that calculates directions between locations. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. The Directions API can return multi-part directions using a series of waypoints."

So can I do something like this?
OnlineMapsGoogleDirections query = OnlineMapsGoogleDirections.Find(
                                new Vector2( (float)point0.long, (float)point0.lat ),
                                new Vector2( (float)point1.long, (float)point1.lat ),
                                new Vector2( (float)point2.long, (float)point2.lat ),
                                new Vector2( (float)point3.long, (float)point3.lat ),
);


Many thanks,

Re: How to add my Google Developers key?

Hello.

Example:

using UnityEngine;

public class GoogleDirectionWithKeyExample: MonoBehaviour
{
    public string googleApiKey;
    public Vector2 origin;
    public Vector2 destination;

    private void Start()
    {
        OnlineMaps.instance.AddMarker(origin, "Origin");
        OnlineMaps.instance.AddMarker(destination, "Destination");

        // Begin to search a route from Los Angeles to the specified coordinates.
        OnlineMapsGoogleDirections request = OnlineMapsGoogleDirections.Find(
            new OnlineMapsGoogleDirections.Params(
                origin, destination)
            {
                key = googleApiKey,
                /*waypoints = new Vector2[]
                {
                    new Vector2( (float)point1.long, (float)point1.lat ),
                    new Vector2( (float)point2.long, (float)point2.lat )
                }*/
            });

        // Specifies that search results must be sent to OnFindDirectionComplete.
        request.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);
    }
}

P.S. Most likely today a new version will be available through the built-in update system.
It has Key Manager. Specifying a key (for any service) once all your requests will automatically use it.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: How to add my Google Developers key?

Thank you very much Alex!


Best regards,
Acacus