package org.onetwo.common.utils;

import java.text.DecimalFormat;

/**
 * 非原创，来自网络
 */
public abstract class DistanceUtils {
	// 地球平均半径  （米）
    private static final double EARTH_RADIUS = 6378137;
    
    //把经纬度转为度（°）  
    private static double toAngle(double d) {  
        return d * Math.PI / 180.0;  
    }
    
    public static double calcDistance(Double lng1, Double lat1, Double lng2, Double lat2) {
    	if(lng1==null || lat1==null || lng2==null || lat2==null){
    		return Double.NaN;
    	}
        double lat1Angle = toAngle(lat1);  
        double lat2Angle = toAngle(lat2);  
        double latDifferAngle = lat1Angle - lat2Angle;  
        double lngDifferAngle = toAngle(lng1) - toAngle(lng2);  
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(latDifferAngle / 2), 2) + Math.cos(lat1Angle) * Math.cos(lat2Angle) * Math.pow(Math.sin(lngDifferAngle / 2), 2)));  
        s = s * EARTH_RADIUS;  
        DecimalFormat df = new DecimalFormat("#.00");  
        s = Double.parseDouble(df.format(s));  
        return s;
    }
    
	
	private DistanceUtils(){
	}

}

@@ -60,16 +60,67 @@
 ormat;%0A%0A
+import org.onetwo.common.exception.BaseException;%0A%0A
 /**%0A * %E9%9D%9E
@@ -358,24 +358,184 @@
 %0A    %7D%0A    %0A
+    /***%0A     * %E8%AE%A1%E7%AE%97%E4%B8%A4%E4%B8%AA%E5%9D%90%E6%A0%87%E4%B9%8B%E9%97%B4%E7%9A%84%E8%B7%9D%E7%A6%BB%EF%BC%8C%E5%8D%95%E4%BD%8D%EF%BC%9A%E7%B1%B3%0A     * @author weishao zeng%0A     * @param lng1%0A     * @param lat1%0A     * @param lng2%0A     * @param lat2%0A     * @return%0A     */%0A
     public s
@@ -677,16 +677,18 @@
 =null)%7B%0A
+//
     %09%09re
@@ -704,16 +704,183 @@
 le.NaN;%0A
+    %09%09throw new BaseException(%22%E5%8F%82%E6%95%B0%E9%94%99%E8%AF%AF%EF%BC%8C%E5%9D%90%E6%A0%87%E4%B8%8D%E8%83%BD%E4%B8%BA%E7%A9%BA%EF%BC%81%22)%0A    %09%09%09%09%09%09%09.put(%22lng1%22, lng1)%0A    %09%09%09%09%09%09%09.put(%22lat1%22, lat1)%0A    %09%09%09%09%09%09%09.put(%22lng2%22, lng2)%0A    %09%09%09%09%09%09%09.put(%22lat2%22, lat2);%0A
     %09%7D%0A 

fix distance