我对Google和有一个问题。
每次我运行新搜索时,谷歌都会在地图上添加文本“blabla列表”。
如果我运行多个搜索,API会在地图上添加包含这些文本的多个元素。
查看右下角:http://s14.directupload.net/images/141016/raq2cfah.jpg
我如何删除这一层,以便只有其中一个元素在地图上?
发布于 2014-11-12 23:11:54
这个问题是因为每次创建google.maps.places.PlacesService的新实例时都会添加文本“由bla列出”。要解决这个问题,请确保只有PlacesService的一个实例是created.One解决方案,它为我工作,第一次加载变量存储,然后从下一次开始调用它。
//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));
}
这样,“上市”只是第一次出现。
请查看此以获取更多信息,https://groups.google.com/forum/#!topic/google-maps-js-api-v3/sQ-isvqfdBM
https://stackoverflow.com/questions/26402028
复制