google-directions-apigoogle-routes-api

Google Routes API - Get leg startLocation / endLocation as address name


I'm migrating from Google Directions API to Routes API, and I've noticed that the leg objects returned in Routes API only include the latitude/longitude of the start/end location. In Directions API, it returns both the latitude/longitude and the address name. For example :

Directions API response :

"legs": [
    {
        "start_address": "London SW1A 0AA, UK",
        "start_location: {
            "lat": 51.5005477,
            "lng": -0.1261448
        }

Routes API response :

"legs": [
    {
        "startLocation: {
            "latLng": {
                "latitude": 51.5005477,
                "longitude": -0.1261448
            }
        }

Is there anyway to get Routes API to return the start/end address name for each leg? I'm already setting the HTTP header 'X-Goog-FieldMask' to '*' to ensure all fields are returned.

Thanks.


Solution

  • These fields (legs.end_address and legs.start_address) are not available in the Routes API, see the Response parameter conversions section in the migration guide.

    This is how Routes API response format is, as seen also in its Reference documentation; in each RouteLeg, the startLocation and endLocation fields are Location objects, and those do not have an address.

    More generally, a location is any point, anywhere on Earth, while an address is one way to describe (some) locations. Many locations don't have an address (even if they are accessible by road) and many locations don't have one unique address.

    While not quite as convenient (or cheap) as the legs.end_address and legs.start_address fields in the Directions API, a better selection of (multiple) addresses can be obtained from the Geocoding API. For instance, you can choose whether to show the nearest result, or the smallest one, e.g. for 37.8903,-121.9312 it may be preferable to show "V3R9+4G Clayton, CA" instead of "Meridian Ridge Rd, Clayton, CA".