Topic: Getting Speed Limit

I'm trying to get the current speed limit using the OnlineMapsGoogleRoads module with the code below and the API shows that the GetSpeedLimitResults needs a string response but it is giving me a "Invalid Expression Term 'String' " error for my response variable. Couldn't find any examples so do I have this correct?

private OnlineMapsGoogleRoads.SpeedLimitResult speedLR;


public void ShowSpeedLimit() {
       
    speedLR.speedLimit = OnlineMapsGoogleRoads.GetSpeedLimitResults(string resp);
   
    Debug.Log("ShowSpeedLimit - Speed Limit: " + speedLR.speedLimit.ToString());
    Debug.Log("ShowSpeedLimit - Speed Limit Type: " + speedLR.units.ToString());

    speedLimitData.GetComponent<TMPro.TextMeshProUGUI>().text = speedLR.speedLimit.ToString();

}

Re: Getting Speed Limit

Hello.

GetSpeedLimitResults returns an array of results objects from the response string.

OnlineMapsGoogleRoads.SpeedLimitResult[] results = OnlineMapsGoogleRoads.GetSpeedLimitResults(response);

Full example:

using System;
using UnityEngine;

public class SpeedLimitsExample : MonoBehaviour
{
    private void Start()
    {
        OnlineMapsGoogleRoads request = OnlineMapsGoogleRoads.SpeedLimits(
            OnlineMapsKeyManager.GoogleMaps(), // Key From KeyManager

            // IEnumerable values can be float, double, Vector2 or string.<br/>
            // If values is string, it must contain placeId.<br/>
            // If values is float, double or Vector2, it must contain coordinates.
            new[]
            {
                "ChIJX12duJAwGQ0Ra0d4Oi4jOGE",
                "ChIJLQcticc0GQ0RoiNZJVa5GxU"
            } 
        );
        request.OnComplete += OnRoadsAPIComplete;
    }

    private void OnRoadsAPIComplete(string response)
    {
        try
        {
            OnlineMapsGoogleRoads.SpeedLimitResult[] speedLimits = OnlineMapsGoogleRoads.GetSpeedLimitResults(response);
            foreach (OnlineMapsGoogleRoads.SpeedLimitResult limit in speedLimits)
            {
                Debug.Log(limit.speedLimit);
            }
        }
        catch (Exception e)
        {
            Debug.LogError(response);
        }

    }
}

P.S. This example has not been tested because I do not have a Google Maps Platform Premium Plan and do not have access to Speed limits.

Kind Regards,
Infinity Code Team.

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

Re: Getting Speed Limit

Alex, Thanks Again!

Pointed me in the direction I needed!