views:

115

answers:

1

Excuse my ignorance, I am not even sure of the correct term for this. What I want to do is search by city and state or zip code in my django application and also include results within certain distances of the location (25, 50, 75 miles).

I am guessing you probably need to convert the city and state or zip code to lat and long and then search based on that. Is this correct or what is the best way to accomplish this in a django application? Does any one know of exiting apps that already do this, so I can look at the code?

Thanks for the help.

+2  A: 

You could use GeoDjango, which already includes these features. Otherwise you can do exactly as you said: geocode addresses to get latitude and longitude, then just do the math ;-)

Gabriel Hurley
Can you tell me more about how I would do this with GeoDjango? I took a look at it, but it looks more like it is used for displaying stuff on maps.
Joe
After setting up your models in geodjango, they offer "Spatial Queries" for selecting objects from the database by criteria like distance or geographic area. It's probably overkill for what you want, but I'll tell you from experience that geocoding addresses into lat/long and then doing the math to get nearby objects is not easy to get right.
Gabriel Hurley