Find Map Bounds to display correct zoom level

Feb 1, 2009 at 8:08 PM
I have the latest in version 4 and I am stuck on finding the correct zoom level to include all markers.
I started out finding the center by calculating half the height and width of the map:

int X = Convert.ToInt32(GoogleMap1.Height.Value / 2);
int Y = Convert.ToInt32(GoogleMap1.Width.Value / 2);

but then I am stuck of finding the map boundary latitude and longitude.

I believe with these I can find the map center at least.

Any help would be greatly appreciated. Great control BTW :)
Feb 2, 2009 at 6:23 AM
Edited Feb 2, 2009 at 6:24 AM

Version 4 is still under development and will bring more improvements, features and changes.
I'm just straggling a lack of time recently.
Using version 4 before it is released is not recommended and it is on your own risk.

Back to your issue:
As you know, the Google Map API is client-side (JavaScript).
The GoogleMap Control  initially renders out on the server-side the JavaScript includes and proper settings and configurations for the client-side Google Map API.
There is no way initially to get the map metrics like bounds for example.
Thus you have to make a post back after map is loaded on the client and when all the metrics of the map are available.
The control will persists then those map metrics and you can used then on the server side code.
I would suggest you to take a look at .
That sample page uses user action by clicking on a button to make the post back, but you can change that by adding handler to the server-side event MapLoad.
When a handler to that event exists, then on the client side when map is loaded a post back is triggered and you can get then Bounds of the map on the server-side code and unregister the MapLoad handler.

Hope this helps.



Feb 2, 2009 at 3:30 PM
Thanks for all your efforts. I will post the code once I get it done.