0

这是我的代码。它将我的坐标显示为线。我想在这一行添加信息窗口。当我点击这一行时,它会显示我想要的任何信息。

PS对不起我的英语:(

flightPlanCoordinates = [
                 new google.maps.LatLng(40.9921196514,47.8604733650 ),
                 new google.maps.LatLng(40.9922511293,47.8606186245 ),
                 new google.maps.LatLng(40.9926358563,47.8611079146 ),
                 new google.maps.LatLng(40.9929381070,47.8615028229 ),
                 new google.maps.LatLng( 40.9931715315,47.8620863814 ),
                 new google.maps.LatLng( 40.9933869955,47.8623375976 ),
                 new google.maps.LatLng(40.9936024589,47.8625888155 ),
                 new google.maps.LatLng(40.9942600516, 47.8634730879 ),
                 new google.maps.LatLng(40.9946698905, 47.8639284456),
                 new google.maps.LatLng(40.9951427577,47.8643998201 ),
                 new google.maps.LatLng(40.9956477404 ,47.8648835770),
                 new google.maps.LatLng(40.9959645185, 47.8651699964),
                 new google.maps.LatLng( 40.9962812958, 47.8654564186 ),
                 new google.maps.LatLng( 40.9965401588,47.8657069220 ),
                 new google.maps.LatLng( 40.9970324883 ,47.8661781983),
                 new google.maps.LatLng(40.9972659548, 47.8663989707 ),
                 new google.maps.LatLng(40.9975468767, 47.8664409273),
                 new google.maps.LatLng( 40.9978740427,47.8662277913 ),
                new google.maps.LatLng( 40.9982012084,47.8660150777 ),
                    new google.maps.LatLng( 40.9985497469,47.8658461824),
 new google.maps.LatLng(40.9988327045,47.8660951747),
  new google.maps.LatLng(40.9991045183,47.8664072712),              
   new google.maps.LatLng(40.9992585926,47.8665868156),                 





        ];
        var flightPath = new google.maps.Polyline({
          path: flightPlanCoordinates,
          strokeColor: '#FF0000',
          strokeOpacity: 1.0,
          strokeWeight: 2
        });

        flightPath.setMap(map);
4

1 回答 1

1

您需要向打开信息窗口并显示内容的折线添加“点击”侦听器。像这样的东西(未经测试):

  var infowindow = new google.maps.InfoWindow();
  var contentString ="content for infowindow";
  google.maps.event.addListener(flightPlan,'click', function(event) {
    infowindow.setContent(contentString);
    infowindow.setPosition(event.latLng);
    infowindow.open(map);
  }); 

例子

于 2012-12-23T18:48:57.110 回答