【问题标题】:Access to google maps api directions markers访问谷歌地图 api 方向标记
【发布时间】:2011-04-02 11:51:54
【问题描述】:

我需要为方向标记添加侦听器,但没有任何访问权限。如何访问方向标记,如简单标记?对不起我糟糕的英语,希望你能理解我。

UPD:我创建了一条新路线:

var request = {
    origin: someorigin,
    destination: somedestination,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request, function(response, status){
    if (status == google.maps.DirectionsStatus.OK){
        directionsDisplay.setDirections(response);
    }
});

现在我想访问起点和终点标记。

【问题讨论】:

  • 所以您想根据方向创建起点和终点标记?
  • 不,我想使用绿色的“A”和“B”(起点和终点)标记,就像使用简单的红色标记一样:删除它们或添加侦听器。
  • 所以你无法在路线服务之后访问 someorigin 和 somedestination 标记?
  • 但是 someorigin 和 somedestination - 是一个 LatLng 对象,而不是一个标记。
  • @Ardentum 所以你想知道如何创建标记对吗?

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


【解决方案1】:

您无法访问通过 google.maps.DirectionsRenderer 类添加到地图的标记。但是,您可以使用 suppressMarkers 选项,渲染折线路线,然后使用您自己的事件添加您自己的开始和目的地标记。

希望这会有所帮助。

【讨论】:

  • 谢谢。我想了一下,但是当我想拖动标记时,这个解决方案有一些限制。在这种情况下,我必须使用 setinterval() 并再次渲染路线。
【解决方案2】:

只需使用 css:

有时简单是关键。

A 行是一个表格:

<table id="adp-placemark" class="adp-placemark" jstcache="0">

和B线是:

<table class="adp-placemark" jstcache="0">

所以下面的css会改变标记:

#adp-placemark img, .adp-placemark img {
   display:none;
}
#adp-placemark {
   font-weight: bold;
   padding: 10px 10px 10px 30px;
   background: white url(../images/map_icons/number_1.png) no-repeat left center;
}
.adp-placemark {
   font-weight: bold;
   padding: 10px 10px 10px 30px;
   background: white url(../images/map_icons/number_2.png) no-repeat left center;
}

【讨论】:

    【解决方案3】:

    如果您使用的是 API V3: 您可以在方向显示对象中找到标记。

    他们是:

    directionsDisplay.b.d[0]
    directionsDisplay.b.d[1]
    

    因此,您可以对它们进行更改,例如将它们从地图上移除:

    directionsDisplay.b.d[0].setMap(null);
    directionsDisplay.b.d[1].setMap(null);
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 2013-06-10
      相关资源
      最近更新 更多