計算兩個經緯度的距離
阿新 • • 發佈:2019-02-09
package com.bra.modules.util; /** * Created by lenovo on 2016/5/19. */ import java.text.DecimalFormat; public class BaiduAPI { /** * 計算兩點之間距離 * @param * @param * @return 米 */ public static String getDistance(Double longitude,Double latitude,Double addressX, Double addressY){ double lon1 = (Math.PI/180)*longitude; double lon2 = (Math.PI/180)*addressX;//經度 double lat1 = (Math.PI/180)*latitude; double lat2 = (Math.PI/180)*addressY;//維度 //地球半徑 double R = 6371; //兩點間距離 km,如果想要米的話,結果*1000就可以了 double d = Math.acos(Math.sin(lat1)*Math.sin(lat2)+Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1))*R; /* d=d*1000;*/ DecimalFormat df=new DecimalFormat("0.00"); return df.format(d); } }