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 回答