How does "Find Nearby Locations" work?

Currently, most restaurants and other businesses have Find Locations functionality on their sites that list the closest locations for a given / Zip address. How is this implemented? Matching zipcode with a database is a simple but easy way to do, but it may not always work, for example, there may be a branch closer to a given location, but it may be in a different zip code. One approach that comes to my mind is to convert a given zip code / address into map coordinates and list any branches that fall within a predetermined radius. I welcome your thoughts on how this would be implemented. If it is possible to provide more detailed information about the implementation, for example, any web services used, etc.,

+7
algorithm mapping
source share
8 answers

Many geospatial frameworks will help you with this. In the geospatial world, a zip code is just a β€œpolygon”, which is just an area on the map that defines clear boundaries (not a polygon in the mathematical sense). For example, in SQL 2008 space, you can create a new polygon based on the original polygon. This way you can dynamically create a polygon, which is your zip code extended at a certain distance at each point. It takes into account the funky form of the zip code. With an address, its easy because you just create a polygon that is a circle around one point. Then you can make queries that give all the points in the new polygon that you created in any of the methods.

Many of these sites basically just do it. They give you all the points in a five-mile extended polygon, and then maybe a 10-mile extended polygon, etc. Etc. In fact, they do not calculate the distance. Most things on the Internet are not complicated.

You can see some basic examples here to get a general idea of ​​what I'm saying.

+6
source share

There is a standard zipode / location database. Here is one version in the Access format that includes lat / long zipcode, as well as other information. You can then use the PostgreSQL GIS extensions to do a search in places, for example.

(assuming, of course, that you extract the access db and paste into a friendlier database such as PostgreSQL)

+4
source share

First, you geocode the address, translating it (usually) to latitude and longitude. Then you query the nearest neighbor request in your database for points of interest.

Most spatial indexes do not directly support nearest neighbor queries, so the usual approach is to query a limited cell with a reasonable size with a geocoded dot in the center, and then sort the results in memory to select the closest one.

+1
source share

Just as you said. Convert the / ZIP address to the 2D coordinate of the world and compare it with other known locations. Choose the one closest. :) I think some DBs (Oracle, MSSQL 2008) even offer some functions that may help, but I never used them.

0
source share

I think this is pretty universal. They take the address or zipcode and turn it into a "map coordinate" (differs depending on the implementation, possibly lat / long), and then using the "map coordinates" of things in the database, it is easy to calculate the distance.

Note that some bad implementations convert the zipcode to a coordinate representing the center of the zipcode area, which sometimes produces poor results.

0
source share

Your thoughts on how to do this is how I will probably do it. You can geocode co-oridinated for zip and then perform calculations based on this. I know that SQL Server 2008 has some special new features that help you execute queries based on these geocoded lon / lat coordinates.

0
source share

There are actual geometric algorithms and / or data structures that support lower O (...) queries to the closest location for points, lines, and / or regions.

See this book as an example of information about some of them, for example: Voronoi diagrams, quadrants, etc.

However, I think the other answers here are correct in most cases that you found today in the software:

  • geocode (at one point) search area
  • request bounding box to get the initial ball
  • in sorting / selecting memory
0
source share

I had a table that would compile a database table every 6 months, it contained 3 columns, I used it for several clients in Australia, it contained about 40 thousand rows, very easy to run a query. it's pretty fast if you just want to get something from the ground for the client

  • Postal code
  • Postcode
  • Distance

    SELECT Store_ID, Store_AccountName, Store_PostalCode, Store_Address, Store_Suburb, Store_Phone, Store_State, Code_Distance FROM Store, (SELECT Code_To as Code_To, Code_Distance FROM Code WHERE Code_From = @PostalCode UNION ALL SELECT Code_From How Code_To code_tom, code_tom, code_tom, code_tom, code_to SELECT @PostalCode As Code_To, 0 As Code_Distance) Like code WHERE Store_PostalCode = Code_To AND Code_Distance <= @Distance ORDER BY Code_Distance

There could be a lot of optimization you could do to speed up this query!

0
source share

All Articles