The PHP version calculates the range of latitude and longitude based on latitude and longitude and radius.

Source: Internet
Author: User

Baidu Map provides a range of search capabilities, but it uses Baidu's own data, but sometimes we need to use their own data, displayed on the map. For example, given two parameters: Specify a location (latitude and longitude Lnglat at one point) and search radius (r) to search for data in the specified range. There are three basic ways to solve this requirement:
1: According to the map provides a method to calculate the distance between two coordinates, one by two calculate the location of the specified position and our DB location in the distance s, with S and R to compare, if s<r, in the search scope, return to the previous paragraph labeled on the map. This method if the data volume is small, you can try, if the data volume is large, not tested, but can imagine ...

2: Use the search engine's own features, such as SOLR's location-aware search, see article http://www.ibm.com/developerworks/cn/java/j-spatial/

3: If the accuracy requirements are not very high, you can calculate the latitude and longitude according to the latitude and the radius of the specified location, and then determine whether the latitude and longitude in the DB in this range, SQL to query. Here's how this is calculated:

/** * @param lat latitude lon longitude Raidus Unit m * Return MINLAT,MINLNG,MAXLAT,MAXLNG*/ Public functionGetaround ($lat,$lon,$raidus){$PI= 3.14159265;$latitude=$lat;$longitude=$lon;$degree= (24901*1609)/360.0;$raidusMile=$raidus;$dpmLat= 1/$degree;$radiusLat=$dpmLat*$raidusMile;$minLat=$latitude–$radiusLat;$maxLat=$latitude+$radiusLat;$mpdLng=$degree*Cos($latitude* ($PI/180));$dpmLng= 1/$mpdLng;$radiusLng=$dpmLng*$raidusMile;$minLng=$longitude–$radiusLng;$maxLng=$longitude+$radiusLng;Echo $minLat.”#". $maxLat." @ ". $minLng." # ". $maxLng;}
This article fixed link: http://www.ccsbbs.com.cn/archives/4686.html

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.