PHP obtains the data calculation range of the range coordinate based on the longitude and latitude, and can search users.
// Computing range, which can be used for searching users
12345678910111213141516171819202122 |
Function GetRange ($ lat, $ lon, $ raidus) {// calculate the latitude $ degree = (24901 1609)/360.0; $ dpmLat = 1/$ degree; $ radiusLat = $ dpmLat $ raidus; $ minLat = $ lat $ radiusLat; // obtain the minimum latitude. $ maxLat = $ lat + $ radiusLat; // obtain the maximum latitude // calculate the longitude $ mpdLng = $ degree cos ($ lat (PI/180); $ dpmLng = 1/$ mpdLng; $ radiusLng = $ dpmLng $ raidus; $ minLng = $ lon $ radiusLng; // obtain the minimum longitude $ maxLng = $ lon + $ radiusLng; // obtain the maximum longitude // range $ range = array ('minlat' => $ minLat, 'maxlat' => $ maxLat, 'minlon '=> $ minLng, 'maxlon '=> $ maxLng); return $ range ;} |
Obtain all data within the specified range.
123456789 |
$ Result = GetRange (110.325945, 20.031541, 5000); $ where = "('jingdu' ". $ result ['minlat']. "and ". $ result ['maxlat']. ") and ('weidu' ". $ result ['minlon ']. "and ". $ result ['maxlon ']. ")"; $ query = $ db> query ("select from ". DB_PRE. "hospital where $ where order BY id DESC"); while ($ row = $ db> fetch_array ($ query )) {$ list [] = $ row ['all _ name'];} print_r ($ list );
|