【问题标题】:How can i add click listener to google map road? [duplicate]如何将点击监听器添加到谷歌地图道路? [复制]
【发布时间】:2016-08-15 08:06:47
【问题描述】:

我是 Google Maps API 的初学者,我编写了这段 JavaScript 代码来向最终用户展示一个简单的路线图:

var originLatLng = new google.maps.LatLng(OrginLat, OrginLng);
        var destinationLatLng = new google.maps.LatLng(DestLat, DestLng);

            directionsService.route({
                origin: originLatLng,
                destination: destinationLatLng,
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            }, function (response, status) {
                if (status === google.maps.DirectionsStatus.OK) {
                    directionsDisplay.setDirections(response);
                } else {
                    window.alert('Directions request failed due to ' + status);
                }
            });



        }//end of function


现在我想在路上启用点击事件。例如,当用户点击道路时,显示警报。我该如何编写该代码?谢谢大家。

【问题讨论】:

  • 我不知道已经给出了答案..下次我会在给出答案时更加警觉

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


【解决方案1】:

试试这个:

google.maps.event.addListener(map,'click',function(){
    if(map.mapTypeId == "roadmap"){
        alert('ok')
    }
})

【讨论】:

  • 好的,你的代码在点击地图时运行,但我想在点击路演时正常
  • 我不知道它是否可能......对不起,我没有尝试过,但如果我发现任何与你的问题相似的东西,我会发布它
猜你喜欢
  • 2016-04-30
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 2016-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多