You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于MapQuest Directions API返回错误路由点的技术咨询

MapQuest Directions API 返回错误路由点问题

我正在将MapQuest Directions API集成到网站中,但调用API时返回了两个目的地之间的错误路由点。

请求详情

POST请求地址:http://www.mapquestapi.com/directions/v2/route?key=[APIKEY]

请求体:

{
    "locations": [
            {
                "latLng": {
                    "lat":  37.47601247,
                    "lng": 126.96594338
                }
            },
            {
                "latLng": {
                    "lat": 37.4713402954355,
                    "lng": 126.95234849232048
                }
            }
    ],
    "options": {
        "avoids": [],
        "avoidTimedConditions": false,
        "doReverseGeocode": false,
        "enhancedNarrative": true,
        "generalize": 0,
        "narrativeType": "text",
        "routeType": "fastest",
        "shapeFormat": "raw",
        "unit": "k"
    }
}

问题现象

我使用返回结果中maneuvers里的startPoint.lng和startPoint.lat进行处理,发现这些路由点完全偏离了设定的起止坐标。返回的路由点集中在37.48xx, 126.96xx区域,但我的起止点是37.4760,126.9659和37.4713,126.9523,距离偏差明显。

返回结果核心片段:

{
    "route": {
        "shape": {
            "shapePoints": [
                37.483936,
                126.974279,
                37.48681,
                126.96995,
                37.487346,
                126.969139
            ]
        },
        "legs": [
            {
                "maneuvers": [
                    {
                        "startPoint": {
                            "lng": 126.974279,
                            "lat": 37.483936
                        }
                    },
                    {
                        "startPoint": {
                            "lng": 126.969139,
                            "lat": 37.487345999999995
                        }
                    }
                ]
            }
        ],
        "locations": [
            {
                "latLng": {
                    "lat": 37.47601247,
                    "lng": 126.96594338
                }
            },
            {
                "latLng": {
                    "lat": 37.4713402954355,
                    "lng": 126.95234849232048
                }
            }
        ]
    }
}

错误路由图示:
错误路由图示

演示图示:
演示图示

我已经尝试调整过generalize参数,但没有改善。之前一个月还能获取精准的位置信息,现在突然出现这个问题,请问需要调整哪些参数才能获得正确的路由信息?


解决方案

1. 强制使用传入坐标,关闭自动纠偏

在请求的options中添加"ignoreLatLngInput": false,明确告诉API使用你提供的精确坐标,而非自动纠偏到最近道路节点。如果你的起止点在非道路区域(比如园区内部),默认的道路网匹配会导致偏移。

调整后的options片段:

"options": {
    "avoids": [],
    "avoidTimedConditions": false,
    "doReverseGeocode": false,
    "enhancedNarrative": true,
    "generalize": 0,
    "narrativeType": "text",
    "routeType": "fastest",
    "shapeFormat": "raw",
    "unit": "k",
    "ignoreLatLngInput": false
}

2. 标记坐标为手动拖拽点

在每个locations条目里添加"dragPoint": true,告知API这些是手动指定的固定点,无需优化调整:

"locations": [
        {
            "latLng": {
                "lat":  37.47601247,
                "lng": 126.96594338
            },
            "dragPoint": true
        },
        {
            "latLng": {
                "lat": 37.4713402954355,
                "lng": 126.95234849232048
            },
            "dragPoint": true
        }
]

3. 检查坐标系与坐标顺序

确认你的坐标使用WGS84标准坐标系(MapQuest默认),若为其他坐标系(如GCJ-02)需先转换。同时核对lat(纬度)在前、lng(经度)在后的顺序是否正确。

4. 切换到HTTPS端点

将请求地址改为https://www.mapquestapi.com/directions/v2/route?key=[APIKEY],避免HTTP协议可能导致的请求篡改或服务差异。

5. 核实API服务变更

查看MapQuest官方文档确认近期是否有API参数或路由逻辑更新,若有则按最新规范调整请求参数。


内容的提问来源于stack exchange,提问作者dtlam26

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 08:50:30