【问题标题】:Google Maps API, feeding an API into an InfoWindowGoogle Maps API,将 API 输入 InfoWindow
【发布时间】:2014-06-08 14:34:16
【问题描述】:

我正在为大学做一个项目,这个项目是一个 Web 应用程序 Mashup,它必须包含 2 个 API,我正在使用“StatsFc”和“Google Maps”API,这两个 API 都非常容易理解和使用除了我遇到的一个问题。

为了输入特定足球队的下一场比赛赛程,他们告诉您使用此代码:

<!-- Place in the <head> of your page -->
   <script src="//code.jquery.com/jquery-latest.min.js"></script>
   <link rel="stylesheet" href="//api.statsfc.com/widget/next-fixture.css">
   <script src="//api.statsfc.com/widget/next-fixture-1.0.min.js"></script>

   <!-- Place in the <body> of your page -->
   <div id="statsfc-next-fixture"></div>

   <!-- Place just before the closing </body> tag -->
     <script>
      var nextFixture = new StatsFC_NextFixture('API_KEY');
      nextFixture.team = 'Liverpool';
      nextFixture.display('statsfc-next-fixture');
      </script>

我已经遵循了这一点,并且它在页面上的任何 div 中都能完美运行,除了我在谷歌地图信息窗口中的那个:

这是地图部分,现在运行代码时会显示但 API 信息没有输入到 div 中

 function initialize() {
    var myLatlng = new google.maps.LatLng(53.4302988,-2.9616045);
     var mapOptions = {
      zoom: 4,
       center: myLatlng
     };

   var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

   var contentString = '<div id="siteNotice">'+
 '<div id="statsfc-next-fixture">'+

  '</div>'+
  '</div>';

  var infowindow = new google.maps.InfoWindow({
     content: contentString
    });

我不太了解这一点,所以我为我的错误解释提前道歉,我也不知道这是否可行,所以请提供帮助或信息将不胜感激。如果还有什么问题可以问,非常感谢

詹姆斯

【问题讨论】:

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


    【解决方案1】:
    • 确保页面上只有一个 id="statsfc-next-fixture" 的 div

    • 从页面底部移除

      <script>
        var nextFixture = new StatsFC_NextFixture('API_KEY');
        nextFixture.team = 'Liverpool';
        nextFixture.display('statsfc-next-fixture');
        </script>
      
    • 添加到初始化函数的末尾

      var nextFixture = new StatsFC_NextFixture('API_KEY'); nextFixture.team = 'Liverpool'; nextFixture.display('statsfc-next-fixture');

    如果这不起作用,我还有其他一些方法可以让你做到这一点......

    【讨论】:

    • 你说的初始化函数是指谷歌地图吗?
    猜你喜欢
    • 2023-04-11
    • 1970-01-01
    • 2012-01-06
    • 2011-12-09
    • 1970-01-01
    • 2013-01-18
    • 2011-05-16
    • 2016-07-12
    • 2020-09-05
    相关资源
    最近更新 更多