我是Google Maps API(3.0)的新用户。我想基于对Maps API的方向查询来获得停留城市,到目前为止还没有找到关于此特定主题的任何文档。
https://developers.google.com/maps/documentation/javascript/directions#Steps
我正在根据地址A和地址B获得指示。我想知道用户在旅途中会遇到的每个城市。我找到了一些关于路点(中途停留点)的信息,但这些信息与每个站点或街道变化有关。到目前为止,我找不到任何核心对象......
感谢您的时间:)
答案 0 :(得分:7)
我会做什么:
Proof of concept,需要针对您进行搜索的位置类型,距离和区域进行调整。根据路线的使用和长度,沿着道路(100米或1000米)以一定的间隔在点上使用反向地理编码器可能会更好,这可能会更快,并且不会耗尽Places API配额。
答案 1 :(得分:1)
我找到了另一种解决方案。我们可以使用以下两个点获得主要城市 Here Maps Android Guide或Here Maps API request。我使用了API请求
它返回API响应中主要城市的经度和纬度。根据这些数据,我们可以使用Google API的Geocoder查找城市名称
此处的maps API请求网址如下:
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]。动作包含主要内容)
{
"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"
}
}