The database records the latitude and longitude marked by merchants on Baidu (for example: 116.412007, 39.947545)
In the initial idea, to loop the radius with the center point as the center point, and to loop the radius for every pixel added (tentatively 1 meter) and then loop the perimeter to query the merchants of the corresponding points in the database (it is really a long time of cycle work). Similar articles on Baidu Internet have some ideas.
The general idea is to know a central point and a radius. Find the circle contains all the points in the circle parabola. In this way, you need to know the vertex of the diagonal line of the circle required. The problem is: The latitude and longitude are a point, and the radius is a distance, so you cannot add or subtract directly.
/// <summary>
///Latitude and longitude coordinates
/// </summary>
public class Degree
{
public Degree(double x, double y)
{
X = x;
Y = y;
}
private double x;
public double X
{
get { return x; }
set { x = value; }
}
private double y;
public double Y
{
get { return y; }
set { y = value; }
}
}
public class CoordDispose
{
private const double EARTH_RADIUS = 6378137.0;//Earth radius (meters)
/// <summary>
/// Convert the angle number to radian formula
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
private static double radians(double d)
{
return d * / 180.0;
}
/// <summary>
/// The formula for converting radians into angle numbers
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
private static double degrees(double d)
{
return d * (180 / );
}
/// <summary>
/// Calculate the direct distance between two latitudes and longitudes
/// </summary>
public static double GetDistance(Degree Degree1, Degree Degree2)
{
double radLat1 = radians();
double radLat2 = radians();
double a = radLat1 - radLat2;
double b = radians() - radians();
double s = 2 * ((((a / 2), 2) +
(radLat1) * (radLat2) * ((b / 2), 2)));
s = s * EARTH_RADIUS;
s = (s * 10000) / 10000;
return s;
}
/// <summary>
/// Calculate the direct distance between two latitudes and longitudes (google algorithm)
/// </summary>
public static double GetDistanceGoogle(Degree Degree1, Degree Degree2)
{
double radLat1 = radians();
double radLng1 = radians();
double radLat2 = radians();
double radLng2 = radians();
double s = ((radLat1) * (radLat2) * (radLng1 - radLng2) + (radLat1) * (radLat2));
s = s * EARTH_RADIUS;
s = (s * 10000) / 10000;
return s;
}
/// <summary>
/// Calculate four vertices based on a latitude and longitude as the center
/// </summary>
/// <param name="distance">Radius (meters)</param>
/// <returns></returns>
public static Degree[] GetDegreeCoordinates(Degree Degree1, double distance)
{
double dlng = 2 * ((distance / (2 * EARTH_RADIUS)) / ());
dlng = degrees(dlng);//It must be converted into angle number. The original PHP article is not clear and incorrect. Later, lz checked a lot of information and finally got it done.
double dlat = distance / EARTH_RADIUS;
dlat = degrees(dlat);//Convert to angle number
return new Degree[] { new Degree(( + dlat,6), ( - dlng,6)),//left-top
new Degree(( - dlat,6), ( - dlng,6)),//left-bottom
new Degree(( + dlat,6), ( + dlng,6)),//right-top
new Degree(( - dlat,6), ( + dlng,6)) //right-bottom
};
}
}
Test method:
static void Main(string[] args)
{
double a = (new Degree(116.412007, 39.947545), new Degree(116.412924, 39.947918));//116.416984,39.944959
double b = (new Degree(116.412007, 39.947545), new Degree(116.412924, 39.947918));
Degree[] dd = (new Degree(116.412007, 39.947545), 102);
(a+" "+b);
(dd[0].X + "," + dd[0].Y );
(dd[3].X + "," + dd[3].Y);
();
}
Tried many times, the error is about 1 meter
Just get the vertex of the circle
If the database is SQL 2008, you can directly index the latitude and longitude fields in space, so that the performance should be better (not tried)
lz company database is still old. It doesn’t matter. The key is latitude and longitude split calculation, so there is more on the Internet. The last SQL statement implemented in the last implementation is the SQL statement.
SELECT id,zuobiao FROM WHERE zuobiao<>'' AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',1)>116.41021 AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',1)<116.413804 AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',2)<39.949369 AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',2)>39.945721