The Openlayers Geocode module has the ability to auto populate text fields with address information. There is an autocomplete field that sends the information to a Google Geocode and location service. It returns lat, long, address, city, state and country which are used to populate the respective text fields. The returned data is consistent so any address in Boston will return the values Boston, MA, and USA and in Wood Hole the values returned are Woods Hole, MA, and USA.
Wouldn't it be grand to be able to sort through these values using Hierarchical Select on an exposed filter? I don't even know if it's possible to use Hierarchical Select as an exposed filter.
Here is the database table from the geocode address field (notice the last to columns refer to taxonomy ids):
vid nid field_street_value field_city_value field_state_value field_country_value field_address_openlayers_wkt field_text_value field_content_taxonomy_country_value field__content_taxonomy_state_value
14 14 NULL Newport RI USA GEOMETRYCOLLECTION(POINT(-71.3128285 41.4901024)) NULL NULL NULL
17 17 NULL Miami FL USA GEOMETRYCOLLECTION(POINT(-80.1936589 25.7742657)) NULL NULL NULL
18 18 NULL Wood Hole MA USA GEOMETRYCOLLECTION(POINT(-88.7878678 43.7844397)) NULL 1 2
19 19 NULL Boston MA USA GEOMETRYCOLLECTION(POINT(-71.0597732 42.3584308)) NULL 1 2
Here is the term_data table (notice the nice correspondence to field_city_value and field_state_value in the above table):
tid vid name description weight
1 1 USA 0
2 1 MA 0
I think what is important here is that I just typed in Woods Hole (my spelling was corrected by the Google Geo service which creates consistency) and then on another node I typed Boston and it returned all that data and populated the term_data table automatically because I used the autocomplete text field in the Content Taxonomy module with the autocomplete Openlayers Geocode (I changed 2 lines of code, simple) The data is consistent.
What I need to do now is create a parent / child structure between taxonomy terms that are countries (from field_content_taxonomy_country_value) and taxonomy terms that are states (field__content_taxonomy_state_value.)
Here is the term_hierarchy table (notice that there is no parent structure):
tid parent
1 0
2 0
Does anybody have any idea how to do this? Imagine having five thousand nodes that used the Geocode to save the address and to be able to use the Hierarchical Select module to sort by country, state, region, ect. and have Views return the lat / long coordinates as WKT that then becomes a dynamic layer on a map. That would be too awesome.
Comments
Comment #1
wim leersAnything should be possible — HS has an API: see the included API.txt file.
Comment #2
drupalinside commentedSubscribe
Comment #3
Adam S commentedThe mistake I made in the database structure that I showed above is when two different CCK types share a field the field is moved to it's own table in the database.
If your database has a finite number of places then use taxonomy terms for those places and a geo taxonomy module. This makes the Hierarchical Select work out of the box. There are databases of locations out there and with the help of Table Wizard module they can be imported and managed.
On the other hand, if you are allowing people to geo locate on OpenLayers through Google Map Services then just use the Proximity Module. The person types a place (can be mispelled) and google returns the coordinates that is then used with a filter in views to show all results within a proximity in miles or km. It works great in all my testing so far.