百度地图根据两点之间的距离进行排序

private const double EARTH_RADIUS = 6371;
private static double deg2rad(double deg) {
     return (Math.PI / 180.0) * deg;
}
private static double rad2deg(double rad) {
      return rad / (Math.PI / 180.0);
 }

double dlng = 2 * Math.Asin(Math.Sin(distance / (2 * EARTH_RADIUS)) / Math.Cos(deg2rad(lat)));
dlng = rad2deg(dlng);
double dlat = distance / EARTH_RADIUS;
dlat = rad2deg(dlat);

squares[0]--'left-top'{lat+dlat,lng - dlng}/squares[1]--'right-top'{lat + dlat,lng + dlng}/squares[2]--/'left-bottom'{lat - dlat,lng - dlng}/squares[3]--'right-bottom'{lat - dlat,lng + dlng}

string info_sql = "select id,name,address,lng,lat from point where lat<>0 and lat>" + ((point)squares[3]).lat + " and y<" + ((point )squares[0]).lat + " and lng>" + ((point )squares[2]).lng + " and lng<" + ((point )squares[3]).lng + " order by ACOS(SIN((" + lat + " * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((" + lat + " * 3.1415) / 180 ) * COS((lat* 3.1415) / 180 ) *COS((" + lng + " * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380 asc";

你可能感兴趣的:(百度地图)