简体   繁体   English

创建交互式 InfoWindow Google Maps API

[英]Creating an interactive InfoWindow Google Maps API

I'm trying to essentially allow the user to click options in the Google Map infowindow which would alter the content of that infowindow, ie a page a,b,c inside the infowindow which when initially opened starts on a.我试图基本上允许用户点击谷歌地图信息窗口中的选项,这将改变该信息窗口的内容,即信息窗口内的页面 a、b、c,最初打开时从 a 开始。

I've tried using jQuery at the top of the page (outside of the infowindow)我尝试在页面顶部(信息窗口之外)使用 jQuery

of the form形式的

$(document).ready(function(){
$("#other1").click(function(){
   
    
  $("#thingy").slideToggle("slow");
    $("#squirry").slideToggle("slow");
});
    
});

and giving them id="something" inside the contentvar but to no avail I've also tried having javascript of the form并在 contentvar 中给他们 id="something" 但无济于事,我也尝试过使用表单的 javascript

function removeDummy() {
    var elem = document.getElementById('dummy');
    elem.parentNode.removeChild(elem);
    return false;
}

inside the infowindow but I just get a whitescreen of death.在信息窗口内,但我只是得到了死亡的白屏。 Is there anyway you can put javascript within the html within the javascript?无论如何,您可以将 javascript 放入 javascript 中的 html 中吗? or anyway to allow the content of an infowindow to be changed from within the window once its already loaded.或者无论如何允许在信息窗口已经加载后从窗口内更改信息窗口的内容。

Here is the code i'm looking at这是我正在查看的代码

its javascript/html nested inside some php它的 javascript/html 嵌套在一些 php 中

echo "

var myLatLng$i = {lat: $lat[$i], lng: $lng[$i]};     
      
      var image = 'nuticon.png';
        var address$i = new google.maps.Marker({
          position: myLatLng$i,
          icon: image,
          map: map});

      address$i.addListener('click', function() {
          document.getElementById('right-panel').innerHTML = '';

          var contentString$i = 
                    '<div id=\"content\">'+
                    '<div id=\"siteNotice\">'+
                    '</div>'+
                    '<h1 id=\"firstHeading\" align=\"center\" class=\"h3\">$titles[$i] </h1>'+
                    '<table border=\"1\" align=\"center\"><tr><p><td><b>Info</b></td><td> <b>Menu </b></td><td><b>Pictures</b></td></p></tr></table>'+
  '<div id=\"bodyContent\" align=\"center\">'+
  '<p></p>'+
 '<iframe id=\"iframe\" src=\"http://voting.first-jump.com/init.php?a=g&g=1000000000004$i&m=0&n=5&s=25&nosound=1&f=3.png&f_a=&f_b=&f_c=\" allowtransparency=\"true\" hspace=\"0\" vspace=\"0\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" height=\"38\" scrolling=\"no\" width=\"128\"></iframe>'+
 '</div>'+

  '<p align=\"center\" id=\"logo\" ><img src=\"$i.png\" width=\"120\" onclick=\"window()\"></p>'+
  '<p align=\"center\" id=\"weblink\">Website Link: <a href=\"$websites[$i]\">'+
  '$titles[$i]</a> '
  
  '</div>';
           var infoWindow$i = new google.maps.InfoWindow({ 
               
map: map,
content: contentString$i,
maxWidth: 200
      });
infoWindow$i.open(map, address$i);



var directionsService = new google.maps.DirectionsService;

    var directionsDisplay = new google.maps.DirectionsRenderer({
      draggable: false,
      map: map,
      panel: document.getElementById('right-panel')
    });
   directionsDisplay.setOptions( { suppressMarkers: true } );
    directionsDisplay.addListener('directions_changed', function() {
      computeTotalDistance(directionsDisplay.getDirections());
    });

    displayRoute(pos, '$lat[$i],$lng[$i]', directionsService,
        directionsDisplay);
        
  });
   ";
}}}
?>

for those people trying to add tabs to your infowindow, try the infobubble library provided by Google对于那些试图向您的信息窗口添加标签的人,请尝试 Google 提供的 infobubble 库

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html/ http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html/

provides as good a working example as I myself would post.提供了一个和我自己会发布的一样好的工作示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM