问题
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