When i add markers from code behind the map looses options!

Sep 26, 2011 at 10:54 PM
Edited Nov 9, 2011 at 6:20 PM

I got this control and I'm populating it with gmarkers using database informations but when i do this the map looses dragging option, zooming etc...

So basicly it turns into a static map if i add markers behind code...

Now i didnt change any properties from behind code or anything the map is inside an update panel. If i dont add the markers the map works fine i can drag it and zoom in zoom out etc.

 

I dont know what to do,

please help any1...

Update: The soultion has been found. I posted it below.

Nov 9, 2011 at 6:17 PM
Edited Nov 9, 2011 at 6:31 PM

Ok, I have found the problem and here is the code which will bind the google map to a ms sql database:

<cc1:GoogleMap ID="GoogleMap1" EnableGoogleMapState="true"  InsideUpdatePanel="false" Visible="true" runat="server" Width="800px" Height="600px" Key ="The key u get from google" Zoom="6">    </cc1:GoogleMap> // The Code on the aspx page

The InsideUpdatePanel should have been set to false since it is not inside an update panel^^.

// The .cs that goes with the page is below

int i = 0;
                    foreach (RealEstateViewModel realestate in RealEstates)
                    {
                        double lat = 0;
                        double log = 0;
                        if (realestate.Lat!= null && realestate.Log!= null)
                        {
                            Double.TryParse(realestate.Lat.ToString(), out lat);
                            Double.TryParse(realestate.Log.ToString(), out log);
                            if (i == 0 && lat != 0 && log != 0)
                            {
                                i++;
                                GoogleMap1.Latitude = lat;
                                GoogleMap1.Longitude = log;

                            }
                            GoogleMarker g = new GoogleMarker();
                            g.Latitude = lat;
                            g.Longitude = log;
                            g.Clickable = true;


                            HtmlGenericControl titleDiv = new HtmlGenericControl("div");
                            titleDiv.InnerText = realestate.DesriptionOfTitle;
                            titleDiv.Attributes["class"] = "title2";
                            // div for image
                            HtmlGenericControl imageDiv = new HtmlGenericControl("div");
                            imageDiv.Attributes["class"] = "image_left";
                            //the image
                            ASPxImage image = new ASPxImage();
                            image.CssClass = "img_left";
                            image.ImageUrl = realestate.Photo;
                            image.Height = 98;
                            image.Width = 130;
                            image.DescriptionUrl = "details.aspx";

                            imageDiv.Controls.Add(image);

                            HtmlGenericControl MainDiv = new HtmlGenericControl("div");
                            HtmlGenericControl OfferInfoDiv = new HtmlGenericControl("div");
                            OfferInfoDiv.Attributes["class"] = "offer_info";

                            HtmlGenericControl SpanOfferDiv = new HtmlGenericControl("span");
                            SpanOfferDiv.InnerText = "Price: " + realestate.Price + " | Owner: " + realestate.Owner + " | Nr. of rooms: " + realestate.NrRooms;

                            HtmlGenericControl OfferParagraf = new HtmlGenericControl("p");
                            OfferParagraf.InnerText = realestate.DescriptionOfRealEstate;

                            HtmlGenericControl MoreDiv = new HtmlGenericControl("div");
                            MoreDiv.Attributes["class"] = "more";

                            HtmlGenericControl Link = new HtmlGenericControl("a");
                            Link.InnerText = "M� shum�...";
                            Link.Attributes["href"] = "details.aspx";

                            MoreDiv.Controls.Add(Link);

                            OfferInfoDiv.Controls.Add(SpanOfferDiv);
                            OfferInfoDiv.Controls.Add(OfferParagraf);
                            OfferInfoDiv.Controls.Add(MoreDiv);

                            MainDiv.Controls.Add(titleDiv);
                            MainDiv.Controls.Add(imageDiv);
                            MainDiv.Controls.Add(OfferInfoDiv);

                            g.InfoContent.Controls.Add(MainDiv);
                            g.InfoContent.CssClass = "offer_box";
                            GoogleMap1.Markers.Add(g);
                        }
                    }
                if (i == 0)
                {
                    GoogleMap1.Latitude = 42.662493842099050;
                    GoogleMap1.Longitude = 21.163787841796875;
                }
                System.Web.UI.AttributeCollection atributes = GoogleMap1.Attributes;
                GoogleMap1.EnableDragging = true;
                GoogleMap1.EnableScrollWheelZoom = true;
                GoogleMap1.ShowScaleControl = true;

So basicly I had a class called RealEstateViewModel and RealEsatets is the list with those objects. The google map should be positioned some place so in case there were no data >> i==0 than position the google map to some place or it wont work otherwise or just set the default place to the tag but than you cant do any dynamic location on code behind;