【问题标题】:google places api/google maps: "listings by..." doesn't get reset-keeps cluttering the map area [closed]google places api/google maps:“listings by ...”不会被重置-使地图区域变得混乱[关闭]
【发布时间】:2012-06-14 14:00:57
【问题描述】:

我有一个使用地点 API 的网站 pune.org。但是,正如您所看到的,如果我选择标记,则按行列出的列表只会不断添加并最终使整个地图区域变得无用。

如何重置列表,或者理想情况下仅显示当前选择的标记的列表?

谢谢, 桑迪普

【问题讨论】:

    标签: google-maps-api-3 google-places-api


    【解决方案1】:

    您在代码中多次实例化 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);

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 2020-05-11
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      相关资源
      最近更新 更多