Absrtact: The current job is to need mobile phone to find nearby n meters within the merchant, functions such as the database records the business in Baidu Mark latitude and longitude (such as: 116.412007,39.947545), the original idea of the center point as the central point, the radius of the loop, Radius each additional pixel (tentative 1 meters) and then loop around the perimeter, to the database to query the corresponding point of the merchant (really a long cycle of work) on the Internet Baidu similar article has a point of view the general idea is known as a central point, a radius, to find the circle contained in the round parabolic all points, In this case, you need to know the desired vertex of the rounded diagonal, the problem is the latitude and longitude is a point, the radius is a distance
The current job is to need a mobile phone to find nearby stores within n meters, functions such as
The database records the business in Baidu Mark latitude and longitude (such as: 116.412007, 39.947545),
The original idea is to circle the radius with the center point as the central point, and the radius for each additional pixel (tentatively 1 meters) to cycle through the perimeter, to the database to query the corresponding point of the merchant (really a long time cycle of work)
Baidu Similar article on the internet has a point
The idea is to know a center point, a radius, to find the circle contained in the circle of all points in the parabolic, so that you need to understand the required circle of the vertex of the diagonal, the problem is the latitude and longitude is a point, radius is a distance, can not directly add and subtract
Finally find the article you want
Http://digdeeply.org/archives/06152067.html
Refer to the original article LZ changed to C # class
/// <summary> ///latitude and longitude coordinates/// </summary> Public classDegree { PublicDegree (DoubleXDoubley) {X=x; Y=y; } Private Doublex; Public DoubleX {Get{returnx;} Set{x =value;} } Private Doubley; Public DoubleY {Get{returny;} Set{y =value;} } } Public classCoorddispose {Private Const DoubleEarth_radius =6378137.0;//Earth radius (m) /// <summary> ///Convert angle number to Radian formula/// </summary> /// <param name= "D" ></param> /// <returns></returns> Private Static DoubleRadiansDoubled) {returnD * Math.PI/180.0; } /// <summary> ///convert radians to angle number formula/// </summary> /// <param name= "D" ></param> /// <returns></returns> Private Static DoubleDegreesDoubled) {returnD * ( the/Math.PI); } /// <summary> ///calculates the direct distance between two latitude and longitude degrees/// </summary> Public Static Doublegetdistance (degree Degree1, degree Degree2) {DoubleRADLAT1 =radians (degree1.x); DoubleRADLAT2 =radians (degree2.x); DoubleA = RADLAT1-RadLat2; Doubleb = radians (DEGREE1.Y)-radians (DEGREE2.Y); Doubles =2* Math.asin (Math.sqrt (Math.pow (Math.sin (A/2),2) +Math.Cos (RADLAT1)* MATH.COS (RADLAT2) * MATH.POW (Math.sin (b/2),2))); S= S *Earth_radius; S= Math.Round (S *10000) /10000; returns; } /// <summary> ///calculates the direct distance between two latitude and longitude (Google algorithm)/// </summary> Public Static DoubleGetdistancegoogle (degree Degree1, degree Degree2) {DoubleRADLAT1 =radians (degree1.x); DoubleRadLng1 =radians (DEGREE1.Y); DoubleRADLAT2 =radians (degree2.x); DoubleRadLng2 =radians (DEGREE2.Y); Doubles = Math.acos (Math.Cos (RADLAT1) * MATH.COS (RADLAT2) * Math.Cos (RADLNG1-RADLNG2) + Math.sin (RADLAT1) *Math.sin (RADLAT2)); S= S *Earth_radius; S= Math.Round (S *10000) /10000; returns; } /// <summary> ///calculates four vertices at the center of a latitude and longitude/// </summary> /// <param name= "Distance" >radius (m)</param> /// <returns></returns> Public StaticDegree[] Getdegreecoordinates (degree Degree1,Doubledistance) { DoubleDLNG =2* Math.asin (Math.sin (Distance/(2* Earth_radius))/Math.Cos (degree1.x)); DLNG= degrees (DLNG);//must be converted to a number of angles original PHP article this place is not clear, it's not correct. Then LZ checked a lot of information and finally got it done. DoubleDlat = distance/Earth_radius; Dlat= degrees (Dlat);//must be converted into a number of angles return NewDegree[] {NewDegree (Math.Round (degree1.x + Dlat,6), Math.Round (DEGREE1.Y-DLNG,6)),//Left-top NewDegree (Math.Round (Degree1.x-dlat,6), Math.Round (DEGREE1.Y-DLNG,6)),//Left-bottom NewDegree (Math.Round (degree1.x + Dlat,6), Math.Round (Degree1.y + DLNG,6)),//Right-top NewDegree (Math.Round (Degree1.x-dlat,6), Math.Round (Degree1.y + DLNG,6))//Right-bottom }; } } //Calling Methods Static voidMain (string[] args) { DoubleA = Coorddispose.getdistance (NewDegree (116.412007,39.947545),NewDegree (116.412924,39.947918));//116.416984,39.944959 Doubleb = Coorddispose.getdistancegoogle (NewDegree (116.412007,39.947545),NewDegree (116.412924,39.947918)); Degree[] DD= Coorddispose.getdegreecoordinates (NewDegree (116.412007,39.947545),102); Console.WriteLine (A+" "+b); Console.WriteLine (dd[0]. X +","+ dd[0]. Y); Console.WriteLine (dd[3]. X +","+ dd[3]. Y); Console.ReadLine (); }
It's good to get the rounded vertices.
Database If SQL 2008 can be directly spatial index latitude and longitude fields, which should be better performance (not tried)
LZ company database also old 2005 of this also does not matter, the key is the latitude split calculation, this is needless to say that the net is the last implementation of the SQL statement
SELECTId,zuobiao fromDbo.zuobiaoWHEREZuobiao<>"' anddbo. Get_strarraystrofindex (Zuobiao,',',1)>116.41021 anddbo. Get_strarraystrofindex (Zuobiao,',',1)<116.413804 anddbo. Get_strarraystrofindex (Zuobiao,',',2)<39.949369 anddbo. Get_strarraystrofindex (Zuobiao,',',2)>39.945721
Reprint: http://www.cxyclub.cn/n/20556/
GPS location, the method of query –c# near latitude location