Checking nearest branch of a zip code

Asked

Viewed 2,420 times

7

I am working on a course system that has several branches.

Within the register I have a zip code field and I would like him, through this zip code, to find the nearest branch. Is there an API or some way to treat this problem?

  • You need the affiliate to be already proposed during system registration or is an internal system or is a front end for customers??

  • 1

    It’s a front end for customers.

2 answers

6


First, you need to georeference your Zip Codes, and your units, with latitude and longitude. Some databases provide this data, for example, the ZIP CODE (there are other initiatives in this regard, fit a researched).

The biggest problem is that Ceps does not have a direct connection with positioning, only a mere orientation by regions and sub-regions of distribution, which does not serve for much in a large city.

If you can, it’s even better give site users the opportunity to choose their position via im dot on a map, as ZIP codes often span extensive areas, and sometimes even entire cities.

This solved, need to organize your base by the nearest units, for example, discussed in this question:

How to organize by proximity using PHP?

Or even in the case of distances in the national territory (either Brazil or Portugal), the calculations can be simplified using the traditional distance calculation, given by the formula:

 distancia = raiz(  ( x2 - x1 )² + ( y2 - y1 )² )

because probably in these cases the geodesic between the two points can be ignored, since the error rates will fall far short of normal distances between two branches. And even if both are close, it’s probably the case to return both, below a tolerance margin.

  • Traditional distance calculation. Pythagorean theorem.

  • As a matter of fact, if I edited and switched to "Pythagorean Theorem," I would feel compelled to write a² = b² + c² instead. I prefer the chewed formula for the specific case same.

5

See if this information helps anything:

1. x0000-000 (Região)
2. 0×000-000 (Sub-Região)
3. 00×00-000 (Setor)
4. 000×0-000 (Sub-Setor)
5. 0000x-000 (Divisor de sub-setor)
6. 00000-xxx (Identificadores de distribuição)
  • But what about the possible mathematics to determine proximity? A simple subtraction would suffice?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.