添加信息窗口到行[谷歌地图]

时间:2012-12-23 16:14:05

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

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

P.S。对不起我的英文:(

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);

1 个答案:

答案 0 :(得分:1)

您需要在打开"click" listener的折线上添加InfoWindow并显示内容。这样的事情(未经测试):

  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);
  }); 

example