【问题标题】:How to show 2 markers in google map to differentiate origin and destination if destination is very nearby to origin?如果目的地离起点很近,如何在谷歌地图中显示 2 个标记以区分起点和终点?
【发布时间】:2013-03-07 16:12:50
【问题描述】:

我开发了 google api 来查找两个地方之间的路线......但是当起点和目的地非常靠近时,用于目的地的标记仅可见,即 [Marker B] ...起点标记 [Marker A ] 隐藏在目的地 [Marker B] ... 我需要原点 [Marker A] 应该在目的地之外稍微可见 [Marker B] ... 看看我附上的示例图像,只有 Marker B 是可见的... 需要标记 A 也应该是可见的……有可能吗?下面的代码应该做哪些改动?

var myOptions = 
{
    center: new google.maps.LatLng(default_latitude,default_longitude),
    zoom: 4,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("mapp"),myOptions);

var latlng=new google.maps.LatLng(glat,glon);

directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("panel"));
var request = {
  origin: acity,
  destination:latlng,
  travelMode: google.maps.DirectionsTravelMode.DRIVING
};

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

【问题讨论】:

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


    【解决方案1】:
    1. 将 suppressMarkers:true 选项添加到 DirectionRenderer options
    2. 添加您的图标,使zIndex of the "start" marker 大于结束标记的zIndex。

    【讨论】:

    • suppressMarkers 使标记不可见....我需要在地图中标记...但想让 A 和 B 都可见
    • 哦,好吧……实际上我没有标记变量……这些标记是由方向渲染器自动生成的……你能不能给我发一个示例代码,以便我理解轻松...
    • 这里是an example,带有自定义的开始和结束标记。它比您需要的更复杂(它呈现整个路线),但您可以只使用开始/结束标记代码。它也不能确保开始标记的 zIndex 高于结束标记。
    猜你喜欢
    • 2016-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    相关资源
    最近更新 更多