thinkphp for latitude-wide querying

Source: Internet
Author: User

Thinkphp implements nearby queries, such as nearby people and nearby deals.

First, you want to locate the latitude and longitude of the user. The client-side targeting method can be located using the Map API or with the HTML5 browser (less stable and less precise).

Then, the current latitude and longitude, and the distance required to search, calculate a latitude and longitude range, this range is "nearby." An example of this "nearby" is calculated as follows:

/** * * @param $latitude latitude * @param $longitude Longitude * @param radius of $raidus (unit: M) * @return Multitype:number*/     Public functionGetaround ($latitude,$longitude,$raidus){        $PI= 3.14159265; $degree= (24901*1609)/360.0; $dpmLat= 1/$degree; $radiusLat=$dpmLat*$raidus; $minLat=$latitude-$radiusLat; $maxLat=$latitude+$radiusLat; $mpdLng=$degree*Cos($latitude* ($PI/180)); $dpmLng= 1/$mpdLng; $radiusLng=$dpmLng*$raidus; $minLng=$longitude-$radiusLng; $maxLng=$longitude+$radiusLng; return Array(minlat=>$minLat, maxlat=>$maxLat, minlng=>$minLng, maxlng=>$maxLng); }

The obtained latitude and longitude distances are then assembled into SQL. Thinkphp is a good package for SQL conditions, super convenient

$array=$this->getaround ($lat,$LNG, 2000);$condition[' latitude '] =Array(Array(' EGT ',$array[' Minlat ']),Array(' ELT ',$array[' Maxlat ']), ' and ');//(' latitude ' >= Minlat) and (' Latitude ' <=maxlat)$condition[' longitude '] =Array(Array(' EGT ',$array[' MINLNG ']),Array(' ELT ',$array[' MAXLNG ']), ' and ');//(' longitude ' >= minlng) and (' Longitude ' <= maxlng)

thinkphp for latitude-wide querying

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.