Getting Geolocation with Google AJAX API

I currently have some geolocation jquery code to take my Google AJAX API, get values like loc.address.city and loc.address.region and write to a cookie to wherever I am including the area and state. For example:

// Using Google API, determine visitors area and set cookie for later retrieval
jQuery(document).ready(function() {
var location = 'Unable to determine your location.';
if (google.loader.ClientLocation) {
var loc = google.loader.ClientLocation;
var cookieNameA = "area_name"; // Cookie for area
var nDays = 5; // Num of Days before cookie expires
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieNameA+"="+ loc.address.city

+ ";expires="+expire.toGMTString();

}
});

The deal is I want to do all of the cookie writing in PHP but it is extremely hard to find any type of documentation on their site or anyone else’s. How would I get the loc.address.city and loc.address.region in PHP language instead of Javascript from their API?

Use AJAX to send the location you looked up using JavaScript to your PHP script, which then sets the cookies.

http://api.jquery.com/jQuery.ajax/

So you are basically saying that in order to get the Geolocation via their API, it has to be in Javascript and no other way like SOAP or cURL to get it server side? It would be nice if there was a way to get even an XML response to decipher in SimpleXML.

There are other sites that bring back Geolocation results like ipinfodb.com but Google is pretty up to date with their maps right?

I’m sure you could reverse engineer their JavaScript library and reimplement it in another language. You’ll have to worry about having your IP blocked if you make a lot of requests, since Google’s AJAX APIs are run directly by the client’s own browser using their IP for the requests.

Thanks for clarifying. I think for now I will keep what I have going with jQuery and let it set cookies in JavaScript. Then from there I can use that cookie value for conversions.