LoginSignup
13
14

More than 5 years have passed since last update.

画面上に表示されている範囲内のマーカーだけ表示する

Posted at

よく使うわりに忘れるのでメモ

画面上に表示されている範囲内のマーカーだけ表示する。
範囲外のマーカーは非表示にする。

// map       -> google Maps obj
// markers   -> marker Array


google.maps.event.addListener(mapObj, 'idle', function(){
    markers.forEach(function(mk){
        if(map.getBounds().contains(mk.getPosition())){
            mk.setVisible(true);
        }else{
            mk.setVisible(false);
        }
    });
});  
13
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
14