我有一个网站pune.org,使用位置应用程序接口。但是,正如您所看到的,如果我选择标记,则按行列出的内容会不断添加,最终会使整个地图区域变得无用。
如何通过或理想地将列表重置为仅按当前选择的标记显示列表?
谢谢,桑迪普
发布于 2012-06-15 02:19:26
您在代码中多次实例化Places Service,例如,每次平移地图时。您需要在开始时设置一个名为service的全局变量,然后实例化一次Places Service (*在地图初始化期间将是合适的)。然后,您可以简单地在其他函数中调用service.search方法,而不是反复实例化服务。
所以:
var service;
\\Rest of other global variables
function initializeMap(initialLat, initialLng, detectCurrentLocation, radius,
zoomLevel, defaultType) {
initialLocation = new google.maps.LatLng(initialLat, initialLng);
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom : zoomLevel,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
service = new google.maps.places.PlacesService(map); //Only do this once!
...//rest of your code
}然后在代码中删除service = new google.maps.places.PlacesService(map);的其他实例,只调用service.search(request, callback);
https://stackoverflow.com/questions/11034766
复制相似问题