Problem with a method in production

Hi all,

I’m trying to implement the GoogleMapAPI class and having some odd results.

On my local dev machine (where I’ve set up a Google API key, but it still won’t work so I can’t test from) when I use the method getGeocode and pass a variable holding an address, it returns the lat/long coordinate values just fine.

However, when I upload and use on a live production server, the method fails and returns nothing.

Any ideas what could be happening?
Thanks for any help.

Also, any reason why my local Google API key doesn’t work? Thanks.

That code depends on the now deprecated Gmaps Version 2 (v2).

The latest is v3, and no longer requires a key (big win!). Though check the browser support list.

Using v2 though, you need to keep 2 keys, the official one you get from Google for your account tied to your URL and the special “localhost” key, which you get from the API docs somewhere. Try:

Then you have the pain of either detecting which computer is serving the files and loading the correct key, or change it manually whenever you FTP your files to the server.

What a PITA.

That is one good reason to upgrade to v3 and just learn to use the API yourself, IMO.

If you are up for it then heres my guide to essential Gmaps v3 Gotchas.

I think using the API is going to be pointless if my server is being blocked by Google.

I saw this in the log files.

[26-Jul-2010 20:55:57] PHP Warning: file_get_contents( [<a href=‘function.file-get-contents’>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

not too promising…

Thank you Cups.

I have a book from 2009 explaining how to use the PHP class and it’s already outdated…sheesh. :rolleyes:

Really though, my concern isn’t for the API key. Why the getGeocode() method in the class doesn’t work on a live server is my hurdle right now.

Just a simple couple lines to determine coordinates:

$mapCoords = new GoogleMapAPI(); 
$coords = $mapCoords->getGeocode('1012 West State Road 436 Altamonte Springs, FL 32714'); 

From my local machine: array(2) { [“lat”]=> string(10) “28.6652735” [“lon”]=> string(11) “-81.4234214” }

From my live website: bool(false)

I’m on the forum they suggest to use for discussion, but no help over there yet.

I’ve never used that particular service but most others that I have used require a separate credentials be registered per domain. So you could register for a separate API key for your production environment and see if that fixes the issue. You should also be able to further analyze the problem by looking at the error, exception, fault the service provides as feedback for origins of the problem. Again this is only speculation based on the services I have used in the past.