无法就地使用 google 文本搜索 api

Not able to use the google textsearch in place api

我想使用 google 地点库 api 中的 textSearch 方法 maps.I 没有我想要的经度、纬度、地名 search.Now 我只想将请求发送到 google 并使用 results.I 包含脚本

<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?&libraries=places"></script>

但我现在必须使用 PlaceService,为此我认为我需要在我的应用程序中包含我不想要的地图。

var service = new google.maps.places.PlacesService(map);
service.textSearch(request, callback);

我只需要搜索具有经度、纬度和 radius.I 的地方已尝试通过生成 url 并发送 ajax request.But 来直接发出请求return

No 'Access-Control-Allow-Origin' header is present on the requested resource

如何在我的 ember 应用程序中搜索文本?

PlaceService constuctor 需要一个 google.Maps.Map 对象或一个 HTML div(它不是't_have_ 地图,但必须成为它显示警告等的地方)

PlacesService(attrContainer:HTMLDivElement|Map) Creates a new instance of the PlacesService that renders attributions in the specified container.

使用地点图书馆不需要地图。

当您打印结果(没有地图)时,您必须:

  1. 显示 google-标志:https://developers.google.com/maps/documentation/javascript/places#LogoRequirements
  2. 打印属性(如果有的话)。因此,您必须提供一个节点作为 PlacesService
  3. 的参数

service = new google.maps.places.PlacesService(
  document.getElementById('attributions')//attributions-container
);

//send a query
service.textSearch({query:'Whosebug'}, function(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      var item=document.createElement('li');
      item.appendChild(document.createTextNode(results[i].name));
      document.getElementById('results').appendChild(item);
    }
  }
});
<script src="https://maps.googleapis.com/maps/api/js?v=3&libraries=places"></script>
<strong>Search for &quot;Whosebug&quot; </strong><br/>

<!-- google-logo -->
<img src="http://developers.google.com/places/documentation/images/powered-by-google-on-white.png"/>

<ul id="results"></ul>

<!-- attributions-container -->
<div id="attributions" style="background:#f1f1f1">
  You'll see here the attributions when there are any
</div>