最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Google Routes API - Get leg startLocationendLocation as address name - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Jan 29 at 16:23 Jonathan WarehamJonathan Wareham 3,4198 gold badges48 silver badges86 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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".

发布评论

评论列表(0)

  1. 暂无评论