In Google Maps V3, is there a way to check whether a marker is actually present on the map?
I have markers that vanish when clicked. I'd like some logic to check the present visibility of the marker.
For example:
var start_marker = null; start_marker = new google.maps.Marker({ position: location, map: map, clickable: true }); google.maps.event.addListener(start_marker, 'click', function(event) { start_marker.setMap(null); }); // ... Later in code: check whether marker is currently visible. console.log('Type of start_marker is now: ' + typeof(start_marker));
I was hoping this would give me a null type when the marker isn't visible, but in fact it's still an Object.
So, how else can I check whether this particular marker is visible on the map?
Thanks!
Step 1 Go to Add or Edit Map and Scroll down to the 'Infowindow Settings' section. Step 2 Enable the box of 'Hide Markers on Page Load' option. Step 3 Click on Save Map and open it in browser.
To do this you really need to be using a browser like Chrome, Firefox, or Opera. Once you have the page open in those browsers, the quickest way to open the inspector is to right-click somewhere on the page and select Inspect (on Chrome) or Inspect Element (Firefox and Opera).
The Google Maps pin is the inverted-drop-shaped icon that marks locations in Google Maps. The pin is protected under a U.S. design patent as "teardrop-shaped marker icon including a shadow". Google has used the pin in various graphics, games, and promotional materials.
This one-liner will return true
if the marker
's position is contained under the current map
boundary, and return false
if not.
map.getBounds().contains(marker.getPosition())
Hope that helps, Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With