谷歌放置搜索api和“列表由”文本

时间:2014-10-16 10:26:10

标签: google-maps google-places-api

我在使用Google地图和地方搜索API时遇到了问题。

每当我运行新搜索时,Google都会在地图上添加文本“blabla列表”。

如果我运行多个搜索,API会在地图上添加多个带有此文本的元素。

请查看右下角:http://s14.directupload.net/images/141016/raq2cfah.jpg

如何删除此图层,以便地图上只有其中一个元素?

1 个答案:

答案 0 :(得分:1)

问题是因为文本"由bla bla"每次创建google.maps.places.PlacesService的新实例时都会添加。要解决此问题,请确保只创建了PlacesService的一个实例。对我有用的一个解决方案是在第一次加载时使用变量存储,然后在下次启动时调用它。



//Have a local variable
var placesService;

//Method that will be using the search.
performNearbySearch(placesRequest) {

  //Check if the PlacesService is already instantiated else create it. 
  if (!this.placesService) {
    this.placesService = new google.maps.PlacesService(this.gmap);
  }

  //Create a placesRequest
  var request = placesRequest;

  //Call the API.
  this.placesService.nearbySearch(request, < callback Function > , true));
}
&#13;
&#13;
&#13;

这种方式只是第一次出现&#34;列表出现&#34;。

检查以获取更多信息https://groups.google.com/forum/#!topic/google-maps-js-api-v3/sQ-isvqfdBM