This project is read-only.

implementing getBoundsZoomLevel

Feb 11, 2010 at 5:01 AM

Hi Velio,


Firstly thanks for all your work on this GoogleMap Control - it's a wonderful tool!


I'm using primarily because I'm not very good with JS, and am much more comfortable with C#.  The issue I'm having is around auto-zooming the map to fit the markers I dynamically add from a sql server database.


On the post ( you mention:

"First, You can use the Google Maps API function getBoundsZoomLevel(GLatLngBounds bounds).
You can access that by GMap reference of the Google Map control class GoogleMap.

For example, if your GoogleMap control on the page has ID="GoogleMap1",  the JS line should looks like:


Of course, in that case you should know the bounds of the found object."


Since I'm loading the markers via looping through a datatable in the code behind, how exactly would I implement a JS function that 'knows the bounds' once the page has loaded?  I can't find any example on the web that shows how to build a GLatLngBounds array of GLatLng items from the markers that are already on the map having been loaded via code behind - can you (or someone) please give me an example of how I would get such a GLatLngBounds array and use it in conjunction with the function you mention above "GoogleMap1.GMap.getBoundsZoomLevel(bounds)"?

Many thanks

Apr 5, 2010 at 9:01 PM

Hi, I have similar problem. I'm adding markers from the DB in the code behing using Linq. Works great. I would like to set the zoom level on the map based on the markers that have been set, preferably from the code behind right after I've added all the markers.

Did you figure out how to do this.

Thanks. All help is greatly appreciated.

Nov 11, 2010 at 7:58 PM

Anyone find out how to do this? I also need to scale the map to the total amount of markers that are on it.


Jan 27, 2011 at 4:02 PM

See other post:

Thanks to ryan_ca1, I was able to easily get this going...  First thing is to make sure you're getting your Min/Max Lat/Long (named ndMinLat, etc below)...

Also, I added it to the OnClientMapLoad rather than a separate call/function and fixed some little issues I found with his script (if your control isn't named map).  Just change "GoogleMap1" to your map id below and you're set!) have been fixed below in a VB version:


                Dim sbZoomMapScript As New StringBuilder
                With sbZoomMapScript
                    .AppendFormat("var sw = new GLatLng({0}, {1});", ndMinLat, ndMinLong).AppendLine()
                    .AppendFormat("var ne = new GLatLng({0}, {1});", ndMaxLat, ndMaxLong).AppendLine()
                    .AppendFormat("var bounds = new GLatLngBounds(sw, ne);").AppendLine()
                    .AppendFormat("var zoomLevel = {0}.GMap.getBoundsZoomLevel(bounds);", GoogleMap1.ClientID).AppendLine()
                    .AppendFormat("{0}.GMap.setZoom(zoomLevel);", GoogleMap1.ClientID).AppendLine()
                End With

                '\\ set the map to call zoomMap javascriptFunction
                Me.GoogleMap1.OnClientMapLoad &= sbZoomMapScript.ToString


Feb 20, 2012 at 4:02 PM


I came across with the issue that in v6.0 there is no OnClientMapLoad, because I wanted to create some overlaid labels.

Now I am needing also some way to use the getBoundZoomLevel function of the Google Maps API.

Could I do something similar to this last code of TMCentral but in version 6.0.

Many thanks.

Feb 20, 2012 at 4:07 PM

This is a question I asked a few weeks ago, but didn´t get a helpful response. I´m still looking for a solution to this problem.

Apr 6, 2012 at 10:26 PM
Edited Apr 6, 2012 at 10:26 PM

I posted my solution here:

Nov 21, 2012 at 3:55 AM
sullrich wrote:

This is a question I asked a few weeks ago, but didn´t get a helpful response. I´m still looking for a solution to this problem.

Posted mine here too