server-side Googlebounds

Apr 23, 2008 at 3:08 PM

Can you help me ? I want to use "GoogleMap1.Bounds.NorthEast.Longitude;" in C# code but debugger says: "GoogleMap1.Bounds is null."
In client-side code: "alert(map.getBounds().getSouthWest().lat());" runs perfectly.

Have you an idea ?


Best regards,
Apr 24, 2008 at 5:57 AM
Edited Apr 24, 2008 at 5:59 AM

GoogleMap control Bounds property will be available after a postback, there is not way to get that before the code goes to client and map is loaded from Google Maps API.
You can imagine that, the map is not loaded to the server. Server-side code just send some initialize JS code and settings to client browser where the map is actually loaded. After the map is loaded on the client-side, then such a Google Maps API specific data can be reflected and send back to server, if needed there.
So, if you try to get Bounds at once, that would be a problem.
In your case you have to get Bounds after a postback, which can be fired by some client action or if you subscribe to MapLoad server event.
The purpose of MapLoad server event is to fire postback immediately after the map is loaded on the client-side and all data, like Bounds is reflected.

In short, subscribe for MapLoad server-side event and add if(IsPostBack) before to get Bounds

Hope this helps
Apr 25, 2008 at 11:27 PM
Thanks you !!!

I don't know if it's your solution but the method I used is : the hiddens fields same as your exemple clientevent.aspx. After, I had the same problem whit the zoom and the latitude/longitude. The hiddens fields are too many and for me it's a bad programmation. Mapload server event is surely a good alternative but
I could not do it. Have you a exemple of code ?

Thanks, (sorry for my english)
Best regards.
May 2, 2008 at 5:26 PM
I have one more question about clientevent.aspx. Why every time I do a post back (with this line of code <%= this.ClientScript.GetPostBackEventReference(_btnSubmit, "") %>; in __setLocation javascript function), googlemap control have to reset to initial state (Latitude, Longitude)??
Sep 12, 2008 at 2:51 PM

I am having a similar issue with accessing GoogleBounds as well.  I am using version 3.4

On my project:

The page loads to a default location set at the Page_Load event.
The postback happens when the user enters some data.

In the snipit of code below, the first statement in the if block invokes a null reference exception.

                if (IsPostBack)
                {//Set Test Bounds:
                    GoogleMap1.Bounds.NorthEast.Latitude = Convert.ToDouble(41.951982);
                    GoogleMap1.Bounds.NorthEast.Longitude = Convert.ToDouble(-80.56147);
                    GoogleMap1.Bounds.SouthWest.Latitude = Convert.ToDouble(33.7581569);
                    GoogleMap1.Bounds.SouthWest.Longitude = Convert.ToDouble(-86.7533259);

My google map .aspx code is:

                <artem:GoogleMap ID="GoogleMap1" runat="server" EnableDragging="True"
                    EnableInfoWindow="True" EnableMarkerManager="False" EnableScrollWheelZoom="True"
                    InsideUpdatePanel="True" EnableDoubleClickZoom="True" DefaultMapView="Normal" EnableContinuousZoom="False">

When the page first loads, the only interaction I do with the map object is:

            GoogleMap1.Address = "United States";//For testing.  Later, set to client's country.

When I try to invoke the OnMapLoad event, I recieve a runtime error.  There appears to be a comma character at '... "GoogleEvents":{,"ServerEvents" ...'  The run time code is (without the API key value):

var ctl00_cphMarketingContent_GoogleMap1_Map = new Artem.Web.GoogleMap({"Address":"United States","BaseCountryCode":null,"ClientID":"ctl00_cphMarketingContent_GoogleMap1","DefaultMapView":0,"Directions":[],"EnableContinuousZoom":false,"EnableDoubleClickZoom":true,"EnableDragging":true,"EnableGoogleBar":false,"EnableInfoWindow":true,"EnableMarkerManager":false,"EnableScrollWheelZoom":true,"GoogleEvents":{,"ServerEvents":[{"Key":"load","Handler":"__doPostBack('ctl00$cphMarketingContent$GoogleMap1','map_event$load')"}]},"Height":"480px","IsStatic":false,"Key":"","Latitude":0,"Longitude":0,"ShowMapTypeControl":true,"ShowScaleControl":false,"ShowTraffic":false,"Width":"600px","Zoom":4,"ZoomPanType":0});

Also, in the VS designer I see an error: "Error Creating Control - GoogleMap1 Request is not available in this context"

Thanks, in advanced, for any assistance you can provide.

Sep 16, 2008 at 3:50 AM
Edited Sep 16, 2008 at 4:00 AM
I have the same issue. Cannot access the bounds on the buttonclick event(which is a post back)
Please put a code sample of few lines how to resolve the issue on a button click event etc.
Your effort will be highly appreciated.
warm regards