unemployment — 2011-12-27T21:18:23-05:00 — #1
This is more of a logic question. I have built a beta version of my site and I am currently working on getting beta V2 out, but I want to implement location based searching of users (particularly with a google api integration). Aside from the API stuff, how do I perform location based searches on the backend. For instance, I have all of my users locations (city, state, country), but how can I say to grab all users by that state when that state is typed in or grab all users by that city when the city is typed in and the same thing for country? Is there anyway to set this up with a default radius too? So if I search for a town, I get a 20 Mile radius result? I really have no idea how to go about the dynamic look up match. Any good tutorials on this?
raju_gautam — 2011-12-28T00:35:24-05:00 — #2
I am personally not sure about the tutorials but for searching there can be two ways;
1. You can just search normal database search with LIKE in the Query by city/state/country.
2. You have to store latitude, longitude in your database and then search accordingly by converting city/state to lag/long using Google API.
starlion — 2011-12-28T08:40:59-05:00 — #3
The straight lokups are just WHERE clauses on your SQL statement.
a Radius-Based search will rely, as stated, on lat/long conversion, and a bit of math. (Google "haversine formula")