Google地方搜索api和“Listings by”文本 [英] google places search api and "Listings by" Text
问题描述
我对Google地图和地点搜索API存在问题。
每次运行新搜索Google都会在地图上添加文字Listings by blabla 。
如果我运行多个搜索,API会在地图上添加多个包含此文本的元素。
在右下角: http://s14.directupload.net/images/141016/raq2cfah .jpg
如何删除此图层,以便只有其中一个元素位于地图上?
问题是因为每次创建google.maps.places.PlacesService的新实例时都会添加文本由bla bla列出。要解决此问题,请确保只创建PlacesService的一个实例。对我而言,一个解决方案是在第一次加载变量存储时从下次调用它。
//有一个局部variablevar placesService; //将使用search.performNearbySearch(placesRequest){//检查PlacesService已经实例化,否则创建它。 if(!this.placesService){this.placesService = new google.maps.PlacesService(this.gmap); } //创建一个placesRequest var request = placesRequest; //调用API。 this.placesService.nearbySearch(request,< callback Function>,true));}
这种方式仅在第一次出现列表出现。
请查看以下信息获取更多信息 https://groups.google.com/forum/#!topic/google-maps- js-api-v3 / sQ-isvqfdBM
i have a problem with the Google Map and the places search API.
Everytime i run a new search Google adds the Text "Listings by blabla" on the map.
If i run multiple Searches, the API adds multiple Elements with this texts on the map.
Look at the lower right corner: http://s14.directupload.net/images/141016/raq2cfah.jpg
How can i remove this layer, so that only one of this elements is on the map?
The issue is because the Text "Listing by bla bla" is added every time you create a new instance of google.maps.places.PlacesService. To resolve this make sure that only one instance of the PlacesService is created.One solution which worked for me was having a variable store the first time it loads and then call it from next time on.
//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));
}
This way only the first time The "Listing Appears".
Check this for more information https://groups.google.com/forum/#!topic/google-maps-js-api-v3/sQ-isvqfdBM
这篇关于Google地方搜索api和“Listings by”文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!