Filter by zip code or other location-based data retrieval strategies

My small site should combine a list of items from a table using the user's active location as a filter. Think Craigslist where you look for "dvd", but the results are not from all the databases, they are filtered by the location you have selected. My question has 2 levels:

  • Should I go a-la-craigslist and ask users to use a city-level location? My problem is that you need to create what seems like a hard-coded, manual list of locations.
  • I have to go a-la-zipCode. The idea is simply to ask the user to enter their zip code, and then combine all the elements that are at the same or some distance from their zip code.

I seem to prefer the postal code, because it seems to be a more elegant solution, but, as a matter of fact, it is about creating a database of all postal codes and implementing the function provided by postcode 12345, it receives all postal codes at a distance of 1 mile

this should be a fairly common β€œtask”, as many sites need my trip, so I hope not to redo the wheel here.

+4
source share
5 answers

Getting the Zip Code database is not a problem. You can try this for free: http://zips.sourceforge.net/

Although I do not know how relevant this is, or you can use one of many suppliers. We have an annual subscription to ZipCodeDownload.com , and maybe for $ 100 we get monthly updates with the latest Zip Code data complete with the Lat / Longs of Zip Code Center of Gravity.

As for requests for all zip addresses in a certain radius, you will need some spatial library. If you just have a table with zips with lats / longs, you will need a database oriented mechanism. SQL Server 2008 has the built-in feature of both open source and commercial libraries that will add such features to SQL Server 2005. The open source PostgreSQL database has a PostGIS project that adds this feature to this database. It is here: http://postgis.refractions.net/

Other database platforms probably have similar designs, but the ones I know about. With one of these database-based libraries, you should be able to directly query any postal codes (or any rows of any type that have lat / long columns) within a given radius.

If you want to go a different route, you can use spatial tools with a mapping library. There are also open source options here, such as SharpMap and many others ( Google can help ) that can use the free Tiger maps for the US as a data source. However, this route is somewhat more complicated and perhaps less efficient if you need a radius search.

Finally, you can watch the web service. This, as you say, is a general need, and I believe that there are some web services that you can subscribe to, which can provide all zip codes within a given radius of the provided zip code. A quick Google search showed this: http://www.zip-codes.com/free-zip-code-tools.asp#radius But there are MANY resources that will be used to search on this issue.

+5
source

how on earth to make one [...] implement a function that sets the zip code 12345, receives all zip codes at a distance of 1 mile?

Here is an example of how to do this:

http://www.codeproject.com/KB/cs/zipcodeutil.aspx

0
source

Just being technical ... PostGIS is not a project of the Postgres community ... it is a standalone project built on top of Postgres. If you need help or support with PostGIS, you will want to go to this community instead of Postgres.

0
source

You can use PostGIS. In addition, I used deCarta mapping libraries. They have a technology that allows you to geoxify any arbitrary data type. Then you can query them spatially.

disclaimer: I work for deCarta p>

0
source

Wouldn't it be better to find out which cities are within a 1 mile radius and store this information in a table? Then you do not need to do calculations in the database all the time.

0
source

Source: https://habr.com/ru/post/1276346/


All Articles