Thursday, April 21, 2011

Which Google Maps API key should I use for development?

I got an API key for development using localhost, but I want to be able to hit my server from different machines on my local network so I can test it. When I go via a local 198.162.. IP address on the network Google throws the error saying I need another API key.

What should I be getting for development purposes so a single server instance can be hit from several machines?

From stackoverflow
  • For development purposes, a simple array with all the IPs your server can be called from should do the trick:

    $keys = array("127.0.0.1" => "google key here", "192.168.0.1" => "google key here");
    $key_to_use = $keys[$_SERVER["HTTP_HOST"]];
    

    Note that HTTP_HOST is a value that can be manipulated freely by the client.

    Daniel Vassallo : This is also another option to my answer. You could determine what API key to use dynamically.
  • I suggest setting up an A record on your local DNS server, which would point to your development server.

    Once you do this, then simply generate a Google Maps API key for your local development domain. As a positive side-effect, this will make it easier for you to transfer your development application to another server, since you will not need to notify all your colleagues with the IP change. You would simply change the record from the DNS server.

0 comments:

Post a Comment