views:

174

answers:

2

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?

A: 

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.

nbv4
I decided to use geopy, but I will give you the best answer since you are the only one who bothered to answer.
Joe
A: 

Hey gents, this is not an answer entry but I couldn't figure out a way to post a comment on nbv4 's answer here.

I'm new to this and have the same needs as Joe. That said, nbv4 's snippet looks like it doesn't do a "radius" search. If zip is X, then it only gives you results whose zip is X. I was thinking more the lines of "show me all results within a 10, 15, 30 mile distance from X". I apologize in advance if this wasn't what the OP was trying to ask in the first place.

Jay