【问题标题】:Google locations automatic is not working in my php pageGoogle 位置自动在我的 php 页面中不起作用
【发布时间】:2017-10-13 05:54:06
【问题描述】:

我正在使用谷歌自动定位 api,但它没有显示在页面上..你们能找出代码中的问题吗?

我的脚本是:

<script>
        function init() {
            var input = document.getElementById('locationTextField');
            var input2 = document.getElementById('locationTextField2');

             var autocomplete = new google.maps.places.Autocomplete(input);
             var autocomplete = new google.maps.places.Autocomplete(input2);

        }

        google.maps.event.addDomListener(window, 'load', init);
    </script>

我的 html 代码是这样的:

     <input type="text" id="locationTextField" placeholder="Source Location"/>
       <input type="text" id="locationTextField2" placeholder="Destination Location"/>

【问题讨论】:

  • 你的意思是从places库自动完成搜索位置?
  • 是的,我正在使用地点库

标签: php forms api google-api


【解决方案1】:

请在您的站点中使用有效的 api 密钥加载您的脚本,

<script src="https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY>&v=3.exp&sensor=false&libraries=places"></script>

这里是示例(没有 api 密钥仅用于演示):

function initialize() {
  new google.maps.places.Autocomplete((document.getElementById('source')), {
    types: ['geocode']
  });
   new google.maps.places.Autocomplete((document.getElementById('dest')), {
    types: ['geocode']
  });
  
}
google.maps.event.addDomListener(window, 'load', initialize);
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places&dummy=.js"></script>

<input id="source" name="source" value="" type="text" size="50" placeholder="Source" />
<input id="dest" name="dest" value="" type="text" size="50" placeholder="Destincation" />

【讨论】:

  • Hy.....“pac-container pac-logo”类即将到来,但在页脚之后..由于它没有显示在页面上
  • @varsha 没有真正明白,你所说的,上面的例子是否适合你
  • 您是否使用了有效的 api 密钥?
  • hy @3161993 我解决了我的控制台问题,但它仍然无法正常工作
猜你喜欢
  • 1970-01-01
  • 2012-05-14
  • 1970-01-01
  • 2021-11-14
  • 2022-01-18
  • 2014-01-18
相关资源
最近更新 更多