google放置api / google地图:“列表by ...”不会重置 - 保持地图区域的混乱 [英] google places api/google maps: "listings by..." doesn't get reset-keeps cluttering the map area

查看:112
本文介绍了google放置api / google地图:“列表by ...”不会重置 - 保持地图区域的混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用场所API的网站pune.org。正如你所看到的,但是如果我选择了标记,那么按线条列出的列表会不断增加,并最终导致整个地图区域无用。

如何通过或理想地重置列表显示当前所选标记的列表?



感谢,
Sandeep

解决方案

您在代码中多次实例化Places服务,每次地图平移时都是如此。您需要在开始时设置一个名为service的全局变量,然后实例化Places服务一次(*在您的映射初始化过程中将是合适的)。然后,您可以简单地在其他函数中调用 service.search 方法,而不是一遍又一遍地实例化该服务。



<所以:

  var service; 
\\其他全局变量的复制
函数initializeMap(initialLat,initialLng,detectCurrentLocation,radius,$ b $ 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); //只做一次!
... //其余的代码
}

然后删除你的代码中的 service = new google.maps.places.PlacesService(map); 的其他实例,只需调用 service.search(request,callback) ;


I have a website pune.org that uses places API. As you can see however if I select markers the Listings by lines just keep getting added and eventually make the entire map area useless.

How can I reset the Listings by or ideally to just show Listings by of the marker that is currently selected?

Thanks, Sandeep

解决方案

You're instantiating the Places Service several times in your code, every time the map pans for example. You need to set a global variable named service at the beginning, then instantiate the Places Service once (*during your map initialization would be appropriate). Then you can simply call the service.search method in your other functions, rather than instantiating the service over and over.

So:

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
}

Then remove the other instances of service = new google.maps.places.PlacesService(map); in your code and only call service.search(request, callback);

这篇关于google放置api / google地图:“列表by ...”不会重置 - 保持地图区域的混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆