0

マップにオーバーレイやマーカーがあるかどうかを確認できる Goole Map API のメソッドはありますか? 次のようなもの:

map.overlaysExist() // #=> true | false
// or
map.overlays()  // #=> [overlayOne, overlayTwo, ...]

次に、次の方法で確認できます。

if(map.overlaysExist()) { ... do something }
// or
if((map.overlays()).length > 0) { ... do something }
4

1 に答える 1

1

You can use map.getBounds().contains(marker.getPosition()) to check if there are any markers on the map, so you could do:

if(map.getBounds().contains(marker.getPosition())) {
   //do stuff
} 

If you just want to check that it exists at all you could just search for the specific variable you are expecting (assuming you are creating the elements as well), e.g.

var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: 'Uluru (Ayers Rock)'
 });

then

if(marker){
   //if the Marker object exists, do something
}
于 2013-10-21T12:26:38.293 に答える