location based search

We currently have a site where objects can be searched for by location. We have a search box and a dropdown of states in our country. Each object has a relationship with one state (states are entities in our database).

We would like to make the site expandable into other countries. Our choices appear to be:

1/ For each country we want to go in to, we need a list of states and possibly post codes. The objects are associated with states and postcodes and a dropdown is provided alongside the search box.

2/ Associate a longitude and latitude to each object and have google api return a longitude and latitude for the address a user types when they search. Then find the objects which fall within a certain radius of the long/lat of the searched address.


Option 1 would perform well but is limited because we have to do a lot of work before entering each country (getting list of states/postcodes). It would also need all states and postcodes to be stored as entities and relationships created between them and objects being searched. Which is wasteful considering the entity is just storing short text.

Option 2 seems like the most elastic and there would be no limit on going in to a new country. However, it would probably perform poorly if not done well.

Option 2 would probably need the introduction of new tables with indexed columns storing the lat/lng of each item to the Elgg database. Maybe option 1 could be done like this too.

We like how www.skillpages.com works. Very quick and accurate search and this is something we would like to replicate if we choose option 2.

I have had interest from Evan already about developing this using sphinx. Im getting ready a staging version to show him. Would aooreciate some feedback on the best approach

  • sound like you're looking to store data such as this for searching country, city, lat,lng, etc =>
    country code      : iso country code, 2 characters
    postal code       : varchar(10)
    place name        : varchar(180)
    admin name1       : 1. order subdivision (state) varchar(100)
    admin code1       : 1. order subdivision (state) varchar(20)
    admin name2       : 2. order subdivision (county/province) varchar(100)
    admin code2       : 2. order subdivision (county/province) varchar(20)
    admin name3       : 3. order subdivision (community) varchar(100)
    admin code3       : 3. order subdivision (community) varchar(20)
    latitude          : estimated latitude (wgs84)
    longitude         : estimated longitude (wgs84)

    CT    PCD    PLACENAME                ADM        CD    ADM CD    ADM                        CD    LATI    LONG
    GB    AL3    South East Bedfordshire    England    ENG        00    Central Bedfordshire    KC    51.8479    -0.4474    6
    GB    AL5    South East Bedfordshire    England    ENG        00    Central Bedfordshire    KC    51.8332    -0.3815    6

    AU    0200    Australian National University    Australian Capital Territory    ACT    CANBERRA                        
    AU    2540    Hmas Creswell    Australian Capital Territory    ACT    NEW CNTRY WEST                -35.028    150.5501    
    AU    2540    Jervis Bay    Australian Capital Territory    ACT    NEW CNTRY WEST                -35.028    150.5501   

  • Hi Dhrup

    Do I need to store that though? For option 2, vould I just store the long/lat of each object and use google map api to find the long/lat of address a user has typed... I'd need extra tables with indexed long and lats for objects

  • are you simply researching just coding aspects ? 'google map api' go you know their api limits ? " just store the long/lat of each object and use google map api " you read ;-( Maps API Terms of Service License Restrictions ? -;O

  • Hi Dhrup, I've never used google api but I've used whereis a lot, which is what a lot of companies use in Australia. I presume google api is at least as job.

    Our site iis a jobs and skills site. So say a user enters a job description, and the location of the job e.g. Dublin 4, Ireland, then I presume i can return a loong/lat for that address through google api and store in elgg db. Then when user is searching a location, they type and address and long/lat is returned and compared to long/lat of onjects in elgg db. Is this feasible/best solution?

  • it won;t matter what the user keys into search - if google or whereis blocks yr site for excessive usage -P betcha skillpages.com do not use google maps api`s ;-oO

  • Hi @Dhrup, sorry, haven't been on the community all weekend and didnt see your reply. Regarding skill pages search, when i viewed source i could see references to google map api...so thats why im thinking the locations prompts are dont using google api...

  • @dhrup

    So how would I implement the table you suggested? This would probably require the introduction of a new table to elgg database, would it not? Storing rows as entities and metadata would surely be far too slow....