【发布时间】:2025-12-10 03:50:02
【问题描述】:
在获得路线后,我试图在 Google 地图上获得一条折线。我想使用v3_epoly 沿折线放置标记。
我发现this 的帖子有效,但我发现它并不完全准确。在图像中,Google 路线是浅蓝色,折线是深蓝色:
您可以看到它非常不准确。
这是代码:
directions_service.route(req, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
path = response.routes[0].overview_path;
$(path).each(function(index, item) {
route.getPath().push(item);
bounds.extend(item);
});
route.setMap(map);
map.fitBounds(bounds);
directions_display.setDirections(response);
}
});
有人知道如何提高这种准确性或以另一种方式获得折线吗?
编辑:
我想添加让它工作的代码:
legs = response.routes[0].legs;
$(legs).each(function(index, item) {
steps = item.steps;
$(steps).each(function(index, item) {
path = item.path;
$(path).each(function(index, item) {
route.getPath().push(item);
counter++;
bounds.extend(item);
});
});
});
【问题讨论】:
标签: javascript google-maps-api-3