google places search api and “Listings by” Text

冷暖自知 提交于 2019-12-10 10:51:20

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/26402028/google-places-search-api-and-listings-by-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!