【问题标题】:Clear the directions in google map v3清除谷歌地图v3中的方向
【发布时间】:2013-05-31 07:03:13
【问题描述】:

我们有两个文本框,在两个文本框中给出位置名称并转换为纬度和经度值。并将值传递给下面的函数。第一次方向加载成功,第二次修改文本框的值,会覆盖之前的方向。它没有清除以前加载的方向。我想清除方向并加载新方向。请帮忙。

var directionsService = new google.maps.DirectionsService();  
var directionsDisplay;

function loadDirections(start,end)
{
    directionsDisplay = new google.maps.DirectionsRenderer();
    if (start && end) 
    {
        resultsDiv.update(''); // So we clear the div out ourselves
        var request = {
                origin: start,
                destination: end,
                travelMode: google.maps.TravelMode.DRIVING,
                unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL 
        };
        directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                  directionsDisplay.setDirections(response);
            }
        }); 
        directionsDisplay.setMap(map.map);
        directionsDisplay.setPanel(resultsDiv);
    }
}

【问题讨论】:

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


    【解决方案1】:

    移动这一行:

    directionsDisplay = new google.maps.DirectionsRenderer();
    

    ...loadDirections().

    否则,您将在每个函数调用中使用 DirectionsRenderer 的新实例,这不会覆盖由先前调用中使用的实例创建的路由。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-02
      • 2011-09-15
      • 1970-01-01
      • 2012-05-03
      • 2012-08-12
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多