Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Retrieving the bounds of a google map

Hi,

I have a map named "map1", this shows various markers and clicking these markers causes an event.

To ensure I only load the markers that would be visible on the map, I need to know the bounds of the map (the user has the ability to zoom in and out, and move the map around, so I have to presume the bounds are variable).

I can't seem to work out how to retrieve the bounds of the google map...I have tried the following without success:

Code: Select all

 var bounds = map1.getBounds(); 

or
var bounds = new google.maps.LatLngBounds(); - but this doesnt return my maps bounds....

Can you help please?

many thanks,

Andy.

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Retrieving the bounds of a google map

Don't worry, worked out how to do this - solution below for anyone else needing the bounds:

google.maps.event.addListener(map1, 'bounds_changed', function() {
window.mapbounds=map1.getBounds();

this essentially sets the global variable -mapbounds to what ever the bounds of the map are, even if the user scrolls or zooms the map :-)

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Retrieving the bounds of a google map

Hello Andy!

Thank you for update!

Return to “Issues”