欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

根据经纬度诀别用java和oracle存储过程计算两点距离

更新时间: 2014-01-05 02:04:26 责任编辑: Author_N1

 

根据经纬度分别用java和Oracle存储过程计算两点距离
create or replace procedure SP_GET_DISTANCE
(cx in number,cy in number,sx in number, sy in number,distance out varchar2) 
is
d number;
x number;
y number;
r number;
pi number;
begin
--开始计算
  r:=6371229;--地球半径
  pi:=3.14159265358979323;--圆周率
  x:=(sx-cx)*pi*r*cos((sy+cy)/2*pi/180)/180;
  y:=(sy-cy)*pi*r/180;
  d:=SQRT(power(x,2)+power(y,2));
  distance:=to_char(d,9999999999999.99);
end SP_GET_DISTANCE;


package com.wpn.web.util;

public class Distance {
	private final static double PI = 3.14159265358979323;// 圆周率
	private final static double R = 6371229;  // 地球的半径

	private Distance() {
	}

	/**
	 * 纬度lat 经度lon
	 * @param longt1
	 * @param lat1
	 * @param longt2
	 * @param lat2
	 * @return
	 */
	public static double getDistance(double longt1, double lat1, double longt2, double lat2) {
		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;
	}

	/*public enum GaussSphere {
		Beijing54, Xian80, WGS84,
	}

	private static double Rad(double d) {
		return d * Math.PI / 180.0;
	}
	public static double DistanceOfTwoPoints(double lng1, double lat1, double lng2, double lat2, GaussSphere gs) {
		double radLat1 = Rad(lat1);
		double radLat2 = Rad(lat2);
		double a = radLat1 - radLat2;
		double b = Rad(lng1) - Rad(lng2);
		double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
		s = s * (gs == GaussSphere.WGS84 ? 6378137.0 : (gs == GaussSphere.Xian80 ? 6378140.0 : 6378245.0));
		s = Math.round(s * 10000) / 10000;
		return s;
	}*/
	
	public static void main(String[] arg){
		double longt1 = 116.515502;
		double lat1 = 39.863898;
		double longt2 = 116.304187;
		double lat2 = 40.052584;
		System.out.println(getDistance(longt1,lat1,longt2,lat2));
	}
}
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:04:26
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/5295/
本文WWW.DOC100.NET DOC100.NET版权所有。