4
I am implementing a system as an online delivery, the customer will enter the tool and put his ZIP code, with this the system should inform all restaurants/ companies, next to it. I was wondering if anyone had a good solution to this search. My main idea was, to save in the database all the companies, with their ZIP codes and the maximum delivery radius, when the customer made the search with his ZIP code, would bring all the companies from the bank and then to each company I would use a Webservice that returns me the distance between the CEPS. However, this solution does not seem to me to be at all efficient. Would anyone know any way to implement this?
The post office has base and service to get zip code, gives a peek at their website. Now remember that a zip code is something that covers a very large area, not a point - distance calculations based on zip code will not be accurate and can give absurd results.
– Oralista de Sistemas
do you want the zip code or the distance between them ?
– Otto
I don’t want a zip code, I want an efficient way to list all the establishments next to an address.
– Gabriel Duarte
I found a way to calculate the distance only using google maps, if it helps in any way
– Otto
So man, this I got, the problem is, how am I gonna do the database search? I take all my establishments, then for each record I calculate the distance between them and see if that establishment delivers at that distance? This will be very costly
– Gabriel Duarte
agree with Voce
– Otto
First of all, I suggest making sure it’s really expensive or not. Maybe it’s not, see that example. Now, if it is, one possibility would be to partition your search area. For example, divide your region into a 4x4 grid, and associate each establishment to one or more positions on that grid (i.e. whether the delivery radius intersects that grid or not). The customer will only be in one position, so the number of potential establishments decreases greatly. If this number is still large, subdivide each region into another 4x4 grid, etc.
– mgibsonbr
I think mgibsonbr, told me may be the ideal solution, now I just need to call the webservice once, to turn the cep into lat and lng and then use that query. I haven’t tried it yet but it makes perfect sense.
– Gabriel Duarte