从google map api v3中删除路线

时间:2011-04-13 07:41:10

标签: javascript jquery google-maps google-maps-api-3

我有一个使用API​​ v3的谷歌地图,它可以获取从一个位置到另一个位置的路线。该应用程序运行良好,但获取方向的窗口是地图上的叠加。我喜欢它,所以当这个窗口关闭时,方向将从地图上移除,但其他标记仍然存在。

我尝试了以下内容:

$('#content .close').live('click', function() {
$('#content').hide();
directionDisplay = new google.maps.DirectionsRenderer();
directionDisplay.suppressMarkers = true;
directionDisplay.setMap(map);
return false;
});

这似乎按预期隐藏了窗口,但是从地图中删除路线没有任何问题。

非常感谢任何帮助。

戴夫。

6 个答案:

答案 0 :(得分:49)

您可以将DirectionsRenderer的地图绑定更改为“null”以删除方向叠加

directionDisplay.setMap(null);

答案 1 :(得分:44)

你可以试试这个,而不是丢失对地图的引用

directionDisplay.set('directions', null);

答案 2 :(得分:8)

您还可以使用: directionsDisplay.setDirections({routes: []});

答案 3 :(得分:0)

那应该是:

directionDisplay.setMap(null);

答案 4 :(得分:0)

使用constexpr int into(int a,int b) { int c=a*b; return c; } int main() { // guaranteed to be resolved before main is called static constexpr int x = into(5,5); constexpr const int& n = x; static_assert(n == 25, "whoops!"); } 将删除整个路线渲染器覆盖,包括标记。如果您只想删除保留标记的路线,可以使用directionDisplay.setMap(null);在初始化后更改setOptions的DirectionsRenderer的选项设置

suppressPolylines

(另见我的其他similar answer

答案 5 :(得分:0)

以上都不适合我,这就是我所需要的:

// Clear past routes
    if (directionsDisplay != null) {
        directionsDisplay.setMap(null);
        directionsDisplay = null;
    }
相关问题