Search for nearby strains

Asked

Viewed 2,934 times

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?

  • 1

    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.

  • do you want the zip code or the distance between them ?

  • I don’t want a zip code, I want an efficient way to list all the establishments next to an address.

  • I found a way to calculate the distance only using google maps, if it helps in any way

  • 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

  • agree with Voce

  • 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.

  • 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.

Show 3 more comments

2 answers

4


You need to develop a database that contains the latitudes and longitudes of each of the companies you want to display in the results. When the user informs your address you must integrate with some geolocation service (google maps, for example) and find the latitude and longitude of the user’s address. Based on these two points it is easy to calculate.

Follow this example from Google itself:

https://developers.google.com/maps/articles/phpsqlsearch_v3

3

Using PHP’s GEOIP functions, you may have "but least" an idea of the weight’s position (GPS). In the case of an Android-like app the iPhone and but easy.

After that, in your data table with Resturant, stores.. you need to indicate for each one, the position. Also with GPS.

After that, you will need to calculate the distance between the two (the "customer" and the "store"). Here a small code to calculate distance: http://www.phpsources.org/scripts459-PHP.htm

Taken care of has a lot that do not use the size of the earth/ They give a distance with weak accuracy, which, in case of v, would not be enough.

Browser other questions tagged

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