开发者

geodjango - search by city, state or zip code

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开发者_如何学Go this.

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜