PHP obtains the range coordinate data based on the longitude and latitude.

Source: Internet
Author: User
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 );

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.