// 坐标 10
GPS left_bottom = new ShopAddress().new GPS();
left_bottom.setLatitude(gpsAround.getLatitude().subtract(new BigDecimal(dlat)));
left_bottom.setLongitude(gpsAround.getLongitude().subtract(new BigDecimal(dlng)));
// 坐标 01
GPS right_top = new ShopAddress().new GPS();
right_top.setLatitude(gpsAround.getLatitude().add(new BigDecimal(dlat)));
right_top.setLongitude(gpsAround.getLongitude().add(new BigDecimal(dlng)));
private final static double EARTH_RADIUS = 6371.393;// 地球半径
private static Map<String, GPS> getNearbyGCJ(GPSAround gpsAround) {
if (null == gpsAround) {
return null;
}
// 求东西两侧的的范围边界。在haversin公式中令φ1 = φ2(维度相同),传入的距离为 米,转换为千米
double dlng = 2 * Math.asin(Math.sin((gpsAround.getDistance() / 1000) / (2 * EARTH_RADIUS))
/ Math.cos(gpsAround.getLatitude().doubleValue() * Math.PI / 180));
// 弧度转换成角度
// dlng = Math.toRadians(dlng);
dlng = Math.toDegrees(dlng);
// 然后求南北两侧的范围边界,在haversin公式中令 Δλ = 0
double dlat = (gpsAround.getDistance() / 1000) / EARTH_RADIUS;
// 弧度转换成角度
dlat = Math.toDegrees(dlat);
// 通过计算可以得到上下左右四个点的经纬度,即,两个经度,两个纬度
// 坐标 10
GPS left_bottom = new GPS(
gpsAround.getLongitude().subtract(new BigDecimal(dlng)).setScale(8,
BigDecimal.ROUND_HALF_UP),
gpsAround.getLatitude().subtract(new BigDecimal(dlat)).setScale(8,
BigDecimal.ROUND_HALF_UP));
// 坐标 01
GPS right_top = new GPS(
gpsAround.getLongitude().add(new BigDecimal(dlng)).setScale(8, BigDecimal.ROUND_HALF_UP),
gpsAround.getLatitude().add(new BigDecimal(dlat)).setScale(8, BigDecimal.ROUND_HALF_UP));
Map<String, GPS> gpsMap = new HashMap<>();
gpsMap.put("top", right_top);
gpsMap.put("bottom", left_bottom);
return gpsMap;
}
SELECT
shop_id ,
shop_name ,
lng ,
lat ,
POWER(lat - 40.05748 , 2) + POWER(lng - 116.30759 , 2) * POWER(COS((lat + 40.05748) / 2) , 2) AS distance
FROM
shop_list
HAVING
distance < 1000
ORDER BY
distance
LIMIT 100;