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