【问题标题】:Get Google Maps API search with Zip Code使用邮政编码获取 Google Maps API 搜索
【发布时间】:2017-02-15 13:55:13
【问题描述】:

我需要根据用户提供的邮政编码搜索裁缝。我正在开发 Laravel 框架(第 5 版) 我可以通过 Ajax 成功检索结果,但尝试使用 json 管理它们时遇到问题。

这是我的网址: https://maps.googleapis.com/maps/api/place/textsearch/json?query=coppel+64710&key=AIzaSyBwb9nwAYMYm4cBkGzAFHmVeqwwoAQEIjI&sensor=true

这是我的脚本

<script type="text/javascript">

   function initMap() {
      map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: -34.397, lng: 150.644},
        zoom: 8
      });
   }

   $(document).ready(function() { 
      //the button that activates the search search
      $("#find-tailor").click(function() {
         $.ajax({
            url:  'https://maps.googleapis.com/maps/api/place/textsearch/json?query=tailor+78577&key=AIzaSyBwb9nwAYMYm4cBkGzAFHmVeqwwoAQEIjI&sensor=true',
            type: 'GET',
            dataType: 'jsonp',
            jsonpCallback: 'callback'

        }).done(function(data) {
               console.log(data);
            });             
      });
   });
</script>

//The script to inicializate the map
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB-amPYw4EvJGyYfY16HzhF2lqpw--FcHM&libraries=places&callback=initMap">  </script>

这是我得到的错误

Uncaught SyntaxError: Unexpected token :

但是,如果你输入到 url,它有 json 值 我怎样才能设法得到它们?

提前致谢

【问题讨论】:

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


    【解决方案1】:

    我相信您使用的是 Google Places Java script API ,您的调用方式是错误的。

    请查看link的示例

    【讨论】:

      猜你喜欢
      • 2011-11-28
      • 2011-07-31
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2018-01-03
      • 2013-06-21
      相关资源
      最近更新 更多