浏览 8369 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-04-26
最后修改:2011-05-19
public double distance(double n1, double e1, double n2, double e2) { double jl_jd = 102834.74258026089786013677476285; double jl_wd = 111712.69150641055729984301412873; double b = Math.abs((e1 - e2) * jl_jd); double a = Math.abs((n1 - n2) * jl_wd); return Math.sqrt((a * a + b * b)); } ALTER FUNCTION dbo.fnGetDistance ( @LatBegin REAL , @LngBegin REAL , @LatEnd REAL , @LngEnd REAL ) RETURNS FLOAT AS BEGIN DECLARE @Distance REAL DECLARE @EARTH_RADIUS REAL SET @EARTH_RADIUS = 6378.137 DECLARE @RadLatBegin REAL, @RadLatEnd REAL, @RadLatDiff REAL, @RadLngDiff REAL SET @RadLatBegin = @LatBegin * PI() / 180.0 SET @RadLatEnd = @LatEnd * PI() / 180.0 SET @RadLatDiff = @RadLatBegin - @RadLatEnd SET @RadLngDiff = @LngBegin * PI() / 180.0 - @LngEnd * PI() / 180.0 SET @Distance = 2 * ASIN(SQRT(POWER(Sin(@RadLatDiff / 2), 2) + COS(@RadLatBegin) * COS(@RadLatEnd) * POWER(SIN(@RadLngDiff/2),2))) SET @Distance = @Distance * @EARTH_RADIUS --SET @Distance = Round(@Distance * 10000) / 10000 RETURN @Distance END /** * @param longitude 经度 * @param latitude纬度 * @param range 多少范围内的 **/ public Integer getWhereInfo(double longitude,double latitude,double range){ StringBuffer hql = new StringBuffer(); double jl_jd = 102834.74258026089786013677476285; double jl_wd = 111712.69150641055729984301412873; hql.append("from whereInfo w where sqrt(power((w.longitude-"+longitude+")*"+jl_jd+",2)+power((w.latitude-"+latitude+")*"+jl_wd+",2))<="+range); return this.whereInfoDao.getwhereInfo(hql.toString()); } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2011-04-27
最后修改:2011-04-27
这是不久前在谷歌地图上做二次开发用到的.
private long calDistance(Double a_x_point, Double a_y_point, Double b_x_point, Double b_y_point) { Double R = new Double(6371); Double dlat = (b_x_point - a_x_point) * Math.PI / 180; Double dlon = (b_y_point - a_y_point) * Math.PI / 180; Double aDouble = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(a_x_point * Math.PI / 180) * Math.cos(b_x_point * Math.PI / 180) * Math.sin(dlon / 2) * Math.sin(dlon / 2); Double cDouble = 2 * Math.atan2(Math.sqrt(aDouble), Math .sqrt(1 - aDouble)); long d = Math.round((R * cDouble) * 1000) / 1000; return d; } |
|
返回顶楼 | |
发表时间:2011-04-27
xiaohan1026 写道 这是不久前在谷歌地图上做二次开发用到的.
private long calDistance(Double a_x_point, Double a_y_point, Double b_x_point, Double b_y_point) { Double R = new Double(6371); Double dlat = (b_x_point - a_x_point) * Math.PI / 180; Double dlon = (b_y_point - a_y_point) * Math.PI / 180; Double aDouble = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(a_x_point * Math.PI / 180) * Math.cos(b_x_point * Math.PI / 180) * Math.sin(dlon / 2) * Math.sin(dlon / 2); Double cDouble = 2 * Math.atan2(Math.sqrt(aDouble), Math .sqrt(1 - aDouble)); long d = Math.round((R * cDouble) * 1000) / 1000; return d; } 为什么 返回long 处理呢 。 |
|
返回顶楼 | |
发表时间:2011-05-30
copy
|
|
返回顶楼 | |
发表时间:2011-05-30
JMS_Exception 写道 xiaohan1026 写道 这是不久前在谷歌地图上做二次开发用到的.
private long calDistance(Double a_x_point, Double a_y_point, Double b_x_point, Double b_y_point) { Double R = new Double(6371); Double dlat = (b_x_point - a_x_point) * Math.PI / 180; Double dlon = (b_y_point - a_y_point) * Math.PI / 180; Double aDouble = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(a_x_point * Math.PI / 180) * Math.cos(b_x_point * Math.PI / 180) * Math.sin(dlon / 2) * Math.sin(dlon / 2); Double cDouble = 2 * Math.atan2(Math.sqrt(aDouble), Math .sqrt(1 - aDouble)); long d = Math.round((R * cDouble) * 1000) / 1000; return d; } 为什么 返回long 处理呢 。 北京离上海差不多有1000多km,总不至于说有1,000,000.xxxxxxxxxm 吧 |
|
返回顶楼 | |
发表时间:2011-06-09
orchidblue 写道 JMS_Exception 写道 xiaohan1026 写道 这是不久前在谷歌地图上做二次开发用到的.
private long calDistance(Double a_x_point, Double a_y_point, Double b_x_point, Double b_y_point) { Double R = new Double(6371); Double dlat = (b_x_point - a_x_point) * Math.PI / 180; Double dlon = (b_y_point - a_y_point) * Math.PI / 180; Double aDouble = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(a_x_point * Math.PI / 180) * Math.cos(b_x_point * Math.PI / 180) * Math.sin(dlon / 2) * Math.sin(dlon / 2); Double cDouble = 2 * Math.atan2(Math.sqrt(aDouble), Math .sqrt(1 - aDouble)); long d = Math.round((R * cDouble) * 1000) / 1000; return d; } 为什么 返回long 处理呢 。 北京离上海差不多有1000多km,总不至于说有1,000,000.xxxxxxxxxm 吧 解? |
|
返回顶楼 | |