CoolNLStuff
CoolNLStuff

Reputation: 5

Alert incorrect Googlemaps API Key

I've been implementing googlemaps.subgurim.net asp.net GoogleMaps control into my site.

I've registered multiple GoogleMaps api keys and the "localhost" key works like a charm.

However when deploying the website to the test environment, the key that is used for the test location is indicated as invalid and another key should be used (googlemaps alert window).

I have a switch statement to select the correct key for the control:

string key = String.Empty;
string host = HttpContext.Current.Request.Url.Host; 

switch (host)
{
  case "localhost":
    key = "ABQIAAAABV0N6hZqFdvToZmnKqONpBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxR8MGhdGlGRPYuMFeud_iPH-mzPWA";
    break;
  case "www.testsite.nl":
    key = "ABQIAAAABV0N6hZqFdvToZmnKqONpBQguCwAOsQdPOJztGP-iedH1TwijhQ0aV8pvp5OiKMQPJcTZnfXdbAfAg";
    break;
  case "testsite.nl":
    key = "ABQIAAAABV0N6hZqFdvToZmnKqONpBTi094shgTTUr7bx6oyKnKzigX6jBQeyXRLotcxJ4miLePbFh2dEgP-Dw";
    break;
  case "test.testsite.nl":
    key = "ABQIAAAABV0N6hZqFdvToZmnKqONpBQio1Rv7BiOhQg5wU76PCoSVkqxXhQA-WgjVK6liPIA7-lOoFbDOgfTBg";
    break;
  default:
    key = String.Empty;
    break;
}

In the page I have displayed HttpContext.Current.Request.Url.Host and it is displayed as test.testsite.nl and the corresponding key is also displayed.

Still I get the alert windows indicating that I used an incorrect code.

I've checked the keys ten times for any typo, tried several proposed solutions found on the internet, but no remedy. Any help is welcome.

Upvotes: 0

Views: 434

Answers (1)

free_easy
free_easy

Reputation: 5129

I don't know anything about the asp.net library but it obvious uses Google Maps Javascript API v2, which is deprecated. The current version v3 doesn't need API keys anymore. ( http://code.google.com/apis/maps/documentation/javascript/basics.html)

Maybe you should look for a v3 API solution? I don't think it make sense to implement new stuff with already deprecated APIs.

Upvotes: 1

Related Questions