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