Nearby Merchant algorithms

Source: Internet
Author: User
Shop表存储字段  Lat, Lng

It is now time to use the scheme to page through the calculation of the distance from the SQL statement order by limit but to calculate it within SQL, resulting in a slow query.

There are currently two options

A方案 :  

The front end through the interface to obtain data for paging, using the above two scenarios, is a one-time pull out the data of nearby merchants, then the distance calculation, based on the distance of the order to generate the final array, the data paging should be based on the index of the array to calculate the offset of the paging operation?

Do you have better algorithms for nearby businesses + pagination?
Supplement also requires the ability to search by city and region

Reply content:

Shop表存储字段  Lat, Lng

It is now time to use the scheme to page through the calculation of the distance from the SQL statement order by limit but to calculate it within SQL, resulting in a slow query.

There are currently two options

A方案 :  

The front end through the interface to obtain data for paging, using the above two scenarios, is a one-time pull out the data of nearby merchants, then the distance calculation, based on the distance of the order to generate the final array, the data paging should be based on the index of the array to calculate the offset of the paging operation?

Do you have better algorithms for nearby businesses + pagination?
Supplement also requires the ability to search by city and region

With a relational database, add an index to the latitude-longitude. Near the algorithm can start from the latitude and longitude, with the user's latitude and longitude (x, y) as the benchmark, the scope of the query ((x+/-), Y (+/-)), expand the scope of the search is the X y range of increased.

Use Elasticsearch or SOLR-like search engines that support space.

Previously written about Demo:django ElasticSearch Ionic building a GIS mobile application-Architecture design

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.