停止谷歌地图空闲事件监听器

时间:2015-09-06 07:22:30

标签: javascript angularjs google-maps

我正在使用谷歌'空闲'事件监听器在地图上上传标记(使用angularjs)。我的代码是

$scope.LoadSearchPropertyOnPortFolioSales = function (PropertyName) {

 if(PropertyName == ''){
 google.maps.event.addListener(map, 'idle', function () {
            var PropertyList = PropertyService.GetSearchPropertyForPortfolio($scope.PortfolioId, $scope.PropertyName, this.center.lat(), this.center.lng(), 0.005, 0.005);
                     PropertyList.then(function (pl) {
                         DrawPropertyOnPortFolioSale(pl.data, $scope.PropertyName);
                     },
             });
 }

 else 
 {
     //Stop event listener
 }
}

我希望事件侦听器仅在传递的PropertyName没有值时才起作用。但是当PropertyName中有一些值时我想停止事件监听器。我如何停止事件监听......

1 个答案:

答案 0 :(得分:2)

还有一个函数可以同时删除所有的侦听器:

import java.io.*;
class loop
{
public static void main(String args[])throws IOException
{
    BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
    String temp,name;
    int number,largest,smallest;
    System.out.print("Enter Your Name: ");
    name = cin.readLine();
    int num[] = new int[4];
    System.out.println(name+", Please enter 4 numbers");
    for(int i=0;i<4;i++)
    {   
        System.out.print("Number "+(i+1)+":");
        temp = cin.readLine();
        num[i] = Integer.parseInt(temp);
    }
    largest=num[0];
    smallest=num[0];
    int i;
    for(i=0;i<4;i++)
    {
        if(num[i]>largest)
        {
            largest=num[i];
        }
        else if(num[i]<smallest)
        {
            smallest=num[i];
        }
    }
    System.out.println("Smallest = "+smallest);
    System.out.println("Largest = "+largest);
    System.out.println("The loop has executed "+i+" times");
}   
}

Here's the Google Maps API reference 你可以在那里阅读它。