Use lat/lng without query first

Asked by Bas on 2009-11-21

I would like to store the lat/lng results of the query in the database. Afterwards only to use query again when people add a new address.

Is this something that can be done with the current version (I believe not, because the lat / lng values are protected) and if not, is this something that will be implemented in a future release?

I rather wait for your (excellent) extension to be updated, than that I will fool around....

Thanks in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
Yii GeoCoder Extension Edit question
Assignee:
Brian Armstrong Edit question
Solved by:
Brian Armstrong
Solved:
2009-12-01
Last query:
2009-12-01
Last reply:
2009-12-01

All of the results returned by the query and stored in the protected attributes array are easily accessible to the programmer, in the fashion of Yii, by the use of the magic __get() method. Each of the items can be retrieved as follows.

The accuracy constant value: $result->accuracy;
The latitude in degrees: $result->latitude;
The longitude in degrees: $result->longitude;
The query string as sent to the driver: $result->query;
The query string as returned by the driver: $result->clean_query;
The state returned by the driver: $result->state;
The county (only valid for google driver): $result->county;
The city name: $result->city;
The zip code (as a string): $result->zip;
The street name: $result->street;
The country (will always be US except with google): $result->country;

There are also three special public get* methods to retrieve special information: the accuracy string, the latitude in radians, and the latitude in radians. These get* methods are also accessibly via the magic __get method as follows:

The accuracy string: $result->accuracy_string;
The latitude in radians: $result->latitude_radians;
The longitude in radians: $result->longitude_radians;

With these special items, you do not need to include the '_'. It is there to conform to the coding standard that I used inside the extension, but is removed inside the __get method. So, for example, you can use $result->accuracyString; if you would prefer.

With this knowledge in mind of how to access the internal variables, it should be a simple matter to cache the information using something like the following:

Get user input for address.
Check if address matches a cached cleaned_query or query in database.
If it does, return cached result.
If not, run the query.
If the query is successful, cache result

Bas (basvanvelzen) said : #2

Thanks for your answer. Very helpful.

Sorry it took me so long to respond. I did receive an email notification when you asked the question. I responded as soon as I noticed it, though. Glad I could help.

I didn't* receive an email. Sigh, it's bed time if I'm making typos like that.