how to implement 2 different GoogleMapKeys for domain redirect?

Jul 18, 2010 at 5:19 PM

Hi Velio,

Great work that Map control, thanks a lot for that!

Imagine the following scenario: 2 different domains with a redirect from 1 to the other, so www.thisDomain.dm redirects to www.thatDomain.dm, where the application sits. Now for both domains I have a different GoogleMap key.

How do I get the control to pick the right GoogleMapKey? With Javascript this was not so hard, but in C#? In code behind I can check for the host like this; Request.Url.Host, so if I set the whole map in code behind this should be no problem. However what about the maps that are set in the aspx page??

 

best regards, Robin van Teunenbroek

Jul 26, 2010 at 9:52 AM
Hi, i'am really just 2 weaks that i've worked with googlemap control, and i find out that is a great job (thanks Velio), and about your question, if i'd understood what you want do, maybe it's enough to put the diferents key in each google map control declaration, like this, <artem:GoogleMap ID="GoogleMap1" runat="server" Key="ABQIAAAAv-KeyDomainthis" Width="100%" Height="400 px" Zoom="11"></artem:GoogleMap> and <artem:GoogleMap ID="GoogleMap1" runat="server" Key="ABQIAAAAv-KeyDomainthat" Width="100%" Height="400 px" Zoom="11"></artem:GoogleMap> Another thing, have you had any trouble requesting the key? because it look like after may, 2010 and google declare decrapte ver 2 it's not posible aks for a key. Hope this help you kerio
Jul 26, 2010 at 6:13 PM

Hi Kerio,

 

Thanks for the reply, but that was not quite what I needed... as I said a redirect on the server to another domain needs a valid googlemap key for the redirecting domain and for the redirected domain.

To choose the GoogleMap key based on which domain the request comes from I added this code to my AppConfiguration.cs:

 

public static string GoogleMkey
    {
        get
        {
            string result = HttpContext.Current.Request.Url.Host;

            switch(result)
            {
                case "www.thisdomain.dk":
                    return Convert.ToString(System.Configuration.ConfigurationManager.AppSettings.Get("GMapThisDom"));
                case "www.ThatDom.dk":
                    return System.Configuration.ConfigurationManager.AppSettings.Get("GMapThatDom");
                default:
                    return System.Configuration.ConfigurationManager.AppSettings.Get("GoogleMapKeyLocal");
            }
        
        }
        
    }

this code gets the different keys (also for localhost which would be default) from the appsettings in the web.config.

All the maps are added in code behind because the Latitude and Longitude come from the database , like this:

 

//add map programmatically
                    string key = AppConfiguration.GoogleMkey;//ConfigurationManager.AppSettings["GoogleMapKey"];

                    GoogleMap myAreaMap = new GoogleMap();

                    myAreaMap.ID = "areaMap";
                    myAreaMap.Key = key;

                    etc

regards, Robin

 

 

Jul 27, 2010 at 10:56 AM

Ok, I see the diefrence, and interesting fragment of code of you have solved how.

Regards