Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django, location based searches

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.

like image 839
Joe Avatar asked Jan 11 '10 22:01

Joe


People also ask

Why use GeoDjango?

GeoDjango is a very powerful framework for storing and working with geographic data using the Django ORM. It provides an easy-to-use API to find the distances between two points on a map, areas of polygons, the points within a polygon, and so on.

How do I create a search in Django?

Setup a Django App:Run the following command to create a Django app named searchapp. Run the following command to create the user for accessing the Django database. If you have created the user before then you don't need to run the command. Add the app name in the INSTALLED_APP part of the settings.py file.

How search works in Django?

These are full document-based search solutions. To use them with data from Django models, you'll need a layer which translates your data into a textual document, including back-references to the database ids. When a search using the engine returns a certain document, you can then look it up in the database.


1 Answers

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 ;-)

like image 192
Gabriel Hurley Avatar answered Oct 19 '22 16:10

Gabriel Hurley