Write a thought record to avoid forgetting about nearby

Source: Internet
Author: User

Get_post-> pageindex/pagesize/times

 

$ Base_offset = 0.0006; // minimum reference range
$ Times = 0; // minimum expansion Range Multiple
Pic_cou = 0; // number of photos

// Start from the minimum range and gradually expand the range until the number of photos is sufficient,
While (pic_cou <pageindex * pagesize)
{
$ Times ++; // adds a range.
$ Now_offset = & times * $ base_offset;
$ Pic_cou = $ query-> count (dblat <lat + $ now_offset & dblng <LNG + $ now_offset & dblat> lat-$ now_offset & dblng> LNG-$ now_offset);
}

// Retrieve the photo
$ Pic_arr = $ query-> get (dblat <lat + $ now_offset & dblng <LNG + $ now_offset & dblat> lat-$ now_offset & dblng> LNG-$ now_offset);
// Obtain the distance cyclically
Foreach ($ pic_arr as $ key => $ Val)
{
$ Picture = $ this-> get_app_home_picture_data_new ($ Val); // convert data to the required fields
$ Distance = $ this-> getdistancebetweenpointsnew ($ Val ['address'], $ Val ['address'], $ Lat, $ LNG); // calculates the distance
$ Picture ['meter '] = $ distance ['meters']; // fields required for storing the returned data
$ Data [] = $ picture; // Merge data and change the data to the target data
}

$ DATA = array_sort ($ data, 'meter '); // sort
$ Arr = array_slice ($ arr,); // obtain the required number.

 

Idea of the first version -------- given a coordinate position, the range is extended from the minimum range (such as 100) until the number of queries matches the number of client requests. The query results of each round-robin are not recorded. Only the number of queries is queried, and the quantity is sufficient to request data to the database.
Idea of version 2 -------- add cache, query data directly each round-robin, and then determine whether the quantity is sufficient. If not, continue to fetch. Note that the distance is calculated every time a dataset is retrieved, the dataset records are merged, and then cached or saved to the database so that the next request does not need to be repeated.

 

 

 

 

 

The code is messy. Try it out in a few days.

Write a thought record to avoid forgetting about nearby

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.