【问题标题】:Get stopover towns using the Google Maps API (directions)使用 Google Maps API(路线)获取中途停留城镇
【发布时间】:2013-01-16 12:08:13
【问题描述】:

我是 Google Maps API (3.0) 的新手。我想根据 Maps API 的方向查询来获得中途停留城市,但到目前为止还没有找到关于这个特定主题的任何文档。

https://developers.google.com/maps/documentation/javascript/directions#Steps

我正在根据地址 A 和地址 B 获取方向。我想知道用户在旅途中会经过的每个城市。我发现了一些关于航路点(中途停留)的信息,但这些信息与每个停靠点或街道变化有关。到目前为止我找不到任何核心对象...

【问题讨论】:

    标签: google-maps google-maps-api-3 directions


    【解决方案1】:

    我会做什么:

    1. 使用RouteBoxer 查找包含路线的边界(相当小的边界)
    2. 使用 Places API 在这些范围内返回 city_hall、local_government_office 或图书馆的 types 的 Places(也许稍微调整一下该选择)。
    3. 从这些响应中提取城镇数据,对它们进行排序以获得独特的结果,然后使用它们。

    Proof of concept,需要针对您正在搜索的位置、距离和区域类型进行调整。根据路线的用途和长度,最好在沿道路的某个固定间隔(100 米或 1000 米)的点上使用反向地理编码器,这样可能会更快并且不会用完 Places API配额。

    【讨论】:

    • 添加了概念证明。
    • 这是一个很好的答案,但是对于长途路线,您将如何解决同样的问题?例如。从纽约开车到蒙特利尔,这是一个 374 英里的车程,途经几乎没有任何城市的地区?将其拆分为 374 个一英里的点并为所有这些点使用反向地理编码器是否可行?
    • proof of concept works for me from NYC to Montreal。这只是一个概念证明,如果您有其他限制/考虑因素,您可能需要对其进行修改。如果您对此有疑问,那应该是一个新问题。
    • 这很有帮助,非常感谢!我现在将详细研究它,看看是否可以使用它来解决我的特定问题。我将结束我的另一个问题,再次感谢!
    【解决方案2】:

    我为此找到了替代解决方案。我们可以使用两个点来获取主要城市 Here Maps Android Guide or Here Maps API request .我使用了API请求

    在 API Response 中返回主要城市的经纬度。从这些数据中,我们可以使用 Google API 的 Geocoder 来查找城市名称

    这里的地图 API 请求 URL 是这样的:

    https://route.api.here.com/routing/7.2/calculateroute.json ?app_id={YOUR_APP_ID} &app_code={YOUR_APP_CODE} &waypoint0=geo!52.5,13.4 &waypoint1=geo!52.5,13.45 &mode=fastest;car;traffic:disabled
    

    响应 :(route[0].leg[0].maneuver 包含主要的 ponts)

    {
    "response": {
        "metaInfo": {
            "timestamp": "2019-08-25T11:32:54Z",
            "mapVersion": "8.30.99.156",
            "moduleVersion": "7.2.201933-4954",
            "interfaceVersion": "2.6.66",
            "availableMapVersion": [
                "8.30.99.156"
            ]
        },
        "route": [
            {
                "waypoint": [
                    {
                        "linkId": "+842950268",
                        "mappedPosition": {
                            "latitude": 7.6005434,
                            "longitude": 80.0758708
                        },
                        "originalPosition": {
                            "latitude": 7.5999999,
                            "longitude": 80.0769999
                        },
                        "type": "stopOver",
                        "spot": 0.4595336,
                        "sideOfStreet": "neither",
                        "mappedRoadName": "Kuliyapitiya-Hettipola Road",
                        "label": "Kuliyapitiya-Hettipola Road - B243",
                        "shapeIndex": 0,
                        "source": "user"
                    },
                    {
                        "linkId": "-843192951",
                        "mappedPosition": {
                            "latitude": 7.4799508,
                            "longitude": 80.3700687
                        },
                        "originalPosition": {
                            "latitude": 7.48,
                            "longitude": 80.3699999
                        },
                        "type": "stopOver",
                        "spot": 0.3064516,
                        "sideOfStreet": "right",
                        "mappedRoadName": "",
                        "label": "",
                        "shapeIndex": 313,
                        "source": "user"
                    }
                ],
                "mode": {
                    "type": "fastest",
                    "transportModes": [
                        "car"
                    ],
                    "trafficMode": "disabled",
                    "feature": []
                },
                "leg": [
                    {
                        "start": {
                            "linkId": "+842950268",
                            "mappedPosition": {
                                "latitude": 7.6005434,
                                "longitude": 80.0758708
                            },
                            "originalPosition": {
                                "latitude": 7.5999999,
                                "longitude": 80.0769999
                            },
                            "type": "stopOver",
                            "spot": 0.4595336,
                            "sideOfStreet": "neither",
                            "mappedRoadName": "Kuliyapitiya-Hettipola Road",
                            "label": "Kuliyapitiya-Hettipola Road - B243",
                            "shapeIndex": 0,
                            "source": "user"
                        },
                        "end": {
                            "linkId": "-843192951",
                            "mappedPosition": {
                                "latitude": 7.4799508,
                                "longitude": 80.3700687
                            },
                            "originalPosition": {
                                "latitude": 7.48,
                                "longitude": 80.3699999
                            },
                            "type": "stopOver",
                            "spot": 0.3064516,
                            "sideOfStreet": "right",
                            "mappedRoadName": "",
                            "label": "",
                            "shapeIndex": 313,
                            "source": "user"
                        },
                        "length": 40642,
                        "travelTime": 2159,
                        "maneuver": [
                            {
                                "position": {
                                    "latitude": 7.6005434,
                                    "longitude": 80.0758708
                                },
                                "instruction": "Head <span class=\"heading\">northeast</span> on <span class=\"street\">Kuliyapitiya-Hettipola Road</span> <span class=\"number\">(B243)</span>. <span class=\"distance-description\">Go for <span class=\"length\">604 m</span>.</span>",
                                "travelTime": 52,
                                "length": 604,
                                "id": "M1",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.6054466,
                                    "longitude": 80.0782084
                                },
                                "instruction": "Turn <span class=\"direction\">right</span> onto <span class=\"next-street\">Wariyapola-Hettipola Road</span> <span class=\"number\">(B079)</span>. <span class=\"distance-description\">Go for <span class=\"length\">18.9 km</span>.</span>",
                                "travelTime": 910,
                                "length": 18937,
                                "id": "M2",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.6197481,
                                    "longitude": 80.2457178
                                },
                                "instruction": "Turn <span class=\"direction\">left</span> onto <span class=\"next-street\">Wariyapola-Hettipola Road</span> <span class=\"number\">(B079)</span>. <span class=\"distance-description\">Go for <span class=\"length\">25 m</span>.</span>",
                                "travelTime": 5,
                                "length": 25,
                                "id": "M3",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.6198554,
                                    "longitude": 80.2459216
                                },
                                "instruction": "Take the <span class=\"exit\">3rd exit</span> from Wariyapola Roundabout roundabout onto <span class=\"next-street\">Kurunegala-Padeniya Road</span> <span class=\"number\">(AA010)</span>. <span class=\"distance-description\">Go for <span class=\"length\">19.6 km</span>.</span>",
                                "travelTime": 1039,
                                "length": 19569,
                                "id": "M4",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.4887598,
                                    "longitude": 80.3620291
                                },
                                "instruction": "Continue straight ahead. <span class=\"distance-description\">Go for <span class=\"length\">364 m</span>.</span>",
                                "travelTime": 36,
                                "length": 364,
                                "id": "M5",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.4871719,
                                    "longitude": 80.3648937
                                },
                                "instruction": "Take the <span class=\"exit\">2nd exit</span> from Kurunegala Roundabout roundabout. <span class=\"distance-description\">Go for <span class=\"length\">192 m</span>.</span>",
                                "travelTime": 21,
                                "length": 192,
                                "id": "M6",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.486732,
                                    "longitude": 80.3665352
                                },
                                "instruction": "Take the <span class=\"exit\">3rd exit</span> from A10 roundabout onto <span class=\"next-street\">Kandy Road</span> <span class=\"number\">(A10)</span>. <span class=\"distance-description\">Go for <span class=\"length\">880 m</span>.</span>",
                                "travelTime": 88,
                                "length": 880,
                                "id": "M7",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.4804449,
                                    "longitude": 80.3704727
                                },
                                "instruction": "Turn <span class=\"direction\">right</span>. <span class=\"distance-description\">Go for <span class=\"length\">71 m</span>.</span>",
                                "travelTime": 8,
                                "length": 71,
                                "id": "M8",
                                "_type": "PrivateTransportManeuverType"
                            },
                            {
                                "position": {
                                    "latitude": 7.4799508,
                                    "longitude": 80.3700687
                                },
                                "instruction": "Arrive at your destination on the right.",
                                "travelTime": 0,
                                "length": 0,
                                "id": "M9",
                                "_type": "PrivateTransportManeuverType"
                            }
                        ]
                    }
                ],
                "summary": {
                    "distance": 40642,
                    "trafficTime": 2159,
                    "baseTime": 2159,
                    "flags": [
                        "builtUpArea"
                    ],
                    "text": "The trip takes <span class=\"length\">40.6 km</span> and <span class=\"time\">36 mins</span>.",
                    "travelTime": 2159,
                    "_type": "RouteSummaryType"
                }
            }
        ],
        "language": "en-us"
    }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      • 2013-02-25
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 1970-01-01
      相关资源
      最近更新 更多