0

How can I use geodjango to search by city and state or zip code in my django application? I am very new to geodjango and just trying to wrap my head around what would be involved in this.

Also, does anyone know of an app that already implements this functionality?

Joe
  • 4,553
  • 9
  • 51
  • 57

2 Answers2

1

First thing you need to do is create a ZipCode model which will be table of geometry objects that represent each zipcode. You'll also need to have another model that you'll be searching, which needs to have a geographic location field. Then you'd do something like:

zip = 10010
zipcode = ZipCode.objects.get(number=zip)
Store.objects.filter(coordinates__in=zipcode)

or something to that effect.

priestc
  • 33,060
  • 24
  • 83
  • 117
  • I decided to use geopy, but I will give you the best answer since you are the only one who bothered to answer. – Joe Feb 20 '10 at 22:12
0

I am going to try something similar soon... I have a small database of about 40 locations, and I want the user to be able to filter these 40 locations by entering any zip code or city name, using a function that will return a list of location that are within a 5, 10, 15, 20, etc radius distance.

I am thinking of using geocoding web services to store the lat/lng for each location in the database. Then when the user enters a city name or a zip code, use one web service call to get the latitude/longitude of that, and do a straightforward non-trigonometric distance calculation (driving distance) in a python list comprehension.

So in answer to the question, I think that's what it involves but it could explode pretty fast if there is no way to limit the amount of calculations that need to be done.

user773328
  • 323
  • 5
  • 11