googlemaps / openapi-specification

OpenAPI specification for Google Maps Platform API
Apache License 2.0
102 stars 86 forks source link

Distance is not returning miles even if units=imperial #412

Closed kmmramos closed 1 year ago

kmmramos commented 1 year ago

Currently, we have a method that gets the distance matrix from google distance api.

    public async Task<DistanceMatrix?> GetDistanceMatrix(List<string> rawDestinationAddress,
                                                            string rawOrigin,
                                                            string travelMode = "DRIVING",
                                                            string unitSystem = "imperial")
    {
        var destinationAddress = JsonSerializer.Serialize(rawDestinationAddress.Select(x => HttpUtility.UrlEncode(x)));

        string url = @$"api/distancematrix/json?origins={HttpUtility.UrlEncode(rawOrigin)}
                                                &destinations={destinationAddress}
                                                &travelMode={travelMode}
                                                &units={unitSystem}
                                                &key={Config.Key}";

        return await HttpClient.GetFromJsonAsync<DistanceMatrix>(url);
    }

Even though we're sending in units=imperial, we always get km in distance.text.

Note: We have tested it just using browser and in there, it returns miles but when we use it in our project, we always get km.

May we know what's the right value for units?

wangela commented 1 year ago

Please file this as a bug in the Public Issue Tracker for the Distance Matrix API. This repo is for documentation of the API.