Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all visible markers on current zoom level

Here are some points:

  1. I have some markers on the map and records associated with it on the right panel besides the map. They are connected via numeric id, which is stored as a property of marker.
  2. All the markers are stored in an array.
  3. When the user zooms in the map, records, associated to only visible markers should be shown on the right panel.

So, how to get the list of all visible markers on the current zoom level? I've searched over the internet and didn't find something useful. Some kind of what I'm trying to achieve could be found here

like image 230
nefo_x Avatar asked May 25 '10 16:05

nefo_x


People also ask

What is zoom level in Google map?

The Google Maps API provides map tiles at various zoom levels for map type imagery. Most roadmap imagery is available from zoom levels 0 to 18, for example. Satellite imagery varies more widely as this imagery is not generated, but directly photographed.

Why is my Google Maps zoomed out?

The app does this because you're not in navigation mode, you're browsing the route. It zooms out to fit the entire route on your screen when you reorient the device. If you don't want it to zoom, press the navigation button in the lower right corner and optionally switch off voice navigation.


2 Answers

In Google Maps JavaScript API V3 we can use something like this:

let markers let map let bounds = map.getBounds() markers.filter(m => m.isAdded).forEach(m => {   if (bounds.contains(m.getPosition())) {     // code for showing your object, associated with current marker   } }) 
like image 64
bruha Avatar answered Sep 21 '22 06:09

bruha


Use GMap2.getBounds() to find the bounding box. The use GLatLngBounds.containsLatLng() to check each marker to see if it is visible.

like image 41
Wai Yip Tung Avatar answered Sep 19 '22 06:09

Wai Yip Tung