Google API 3会在一段时间后过期

时间:2012-09-29 12:11:49

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

我正在使用Gmap3-Jquery plugin在我的某个网络应用程序中生成Google地图。 目前,我已将Google API 下载到我的本地驱动器,并在我的HTML页面中使用了相同的内容。

然而,所有操作都适用于我,但3-4天后Google API停止工作。如果我从同一链接下载新的Google API到我的本地驱动器一切正常。可能是造成这种问题的原因是什么?是因为API Key吗?或者是因为我下载到我的本地驱动器并从本地引用它?

但我正在下载谷歌地图API3,它不需要API密钥。

以下是代码:

<script src="/site_media/js/google-map.js" type="text/javascript"></script>
<script type="text/javascript" src="/site_media/js/gmap3.js"></script> 
<script type="text/javascript">
    $(function(){
    $('#facility_map').gmap3(
        {    
      action:'init',
      options:{
                center:[26.327475, 50.20134],
            zoom: 18,
                mapTypeId: google.maps.MapTypeId.HYBRID
          }
        },      
            {
     action:'getRoute',
     options:{
               origin:['26.327475', '50.20134'], 
               destination:['{{facility.latitude}}', '{{facility.longitude}}'],
           travelMode: google.maps.DirectionsTravelMode.DRIVING
              },
     callback: function(results)
        { 
           if (!results) return;
           $(this).gmap3(
            { 
              action:'addDirectionsRenderer',
              options:{      
                            preserveViewport: true,         
                directions:results
                  }
            });
        }   
    },
           {
             action:'getDistance',
             options:{ 
                      origins:[['26.327475', '50.20134']], 
              destinations:[['{{facility.latitude}}', '{{facility.longitude}}']],
              travelMode: google.maps.TravelMode.DRIVING
             },
      callback: function(results)
      {
        var html = '';
        if (results)
            {
          for (var i = 0; i < results.rows.length; i++)
          {
         var elements = results.rows[i].elements;
         for(var j=0; j<elements.length; j++)
         {
            switch(elements[j].status)
           {
             case google.maps.DistanceMatrixStatus.OK:
                  html += results.destinationAddresses[j]+" -<b> "+elements[j].distance.text + ' (' + elements[j].duration.text + '</b>)<br />';
             break;
             case google.maps.DistanceMatrixStatus.NOT_FOUND:
              html += 'The origin and/or destination of this pairing could not be geocoded<br />';
             break;
             case google.maps.DistanceMatrixStatus.ZERO_RESULTS:
                  html += 'No route could be found between the origin and destination.<br />';
              break;
            }
        }
      } 
       } 
        else 
        {
           html = 'error';
         }
         $('#distance_msg').html("Distance From Rezayat Head Office Khobar to "+html);
       }
     }
    ); 
    });


</script>  

1 个答案:

答案 0 :(得分:1)

您是否将以下文件保存到硬盘/网络应用中:

  

http://maps.google.com/maps/api/js?sensor=false

如果是,那么问题的答案就是......

  

还是因为我下载到本地驱动器并引用它   来自当地?

...是的。

您正在引用的文件已缓存,因此它始终在更改。我从来没有使用过你上面提到过的jQuery maps插件(虽然看起来很酷!),但是在查看他们的API时,它提到你应该从Google调用该脚本,而不是直接存储它。

另外,请记住,让Google为您处理JS负载和带宽,并尽量避免在本地存储。 API可能会更改,并且使用您的缓存版本,您的地图可能会中断,因为它没有加载最新版本。

我还要添加一件事:让Google load your jQuery也是如此 - 使用该网站的人将获得更好的体验。本文将详细解释why

相关问题