java通过经纬计算距离的方法

private Double getDistance(String jinwei, String friendCircleJinwei) {
		double PI = 3.14159265358979323; // 圆周率
		double R = 6371229; // 地球的半径
		String str[]=jinwei.split(",");
		double longt1= Double.parseDouble(str[0]);
		double lat1 = Double.parseDouble(str[1]);
		String str2[] = friendCircleJinwei.split(",");
		double longt2=Double.parseDouble(str2[0]);
		double lat2=Double.parseDouble(str2[1]);
        double x, y, distance;
        x = (longt2 - longt1) * PI * R
                * Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
        y = (lat2 - lat1) * PI * R / 180;
        distance = Math.hypot(x, y);
        return distance;
    
	}

java通过经纬计算距离的方法

你可能感兴趣的:(java通过经纬计算距离的方法)