zoukankan      html  css  js  c++  java
  • 如何判断一个GPS点是否在以另一个GPS点为圆心100米为半径的圆内(Java代码)

    题目乍一看,无从下手,仔细想了一下,原来只需要判断两个GPS点的直线距离是否<100米即可。

    Java代码如下:

            /**
    	 * 将两个经纬度坐标转化成距离(米)
    	 * 
    	 * @param 2个GPS经纬度坐标(latitude1,longitude1)(latitude2,longitude2)
    	 * 
    	 * @return true:坐标点异常
    	 * 		   false:坐标点正常
    	 */
    	public static boolean coordinateToDistance(double latitude1, double longitude1, double latitude2, double longitude2)
    	{
    		double a = latitude1 * Math.PI / 180.0 - latitude2 * Math.PI / 180.0;
    		double b = longitude1 * Math.PI / 180.0 - longitude2 * Math.PI / 180.0;
    		double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
    				+ Math.cos(latitude1 * Math.PI / 180.0)
    				* Math.cos(latitude2 * Math.PI / 180.0)
    				* Math.pow(Math.sin(b / 2), 2)));
    		s = s * 6378.137 * 1000;
    		s = Math.round(s);
    		if (s > 500) {
    			return true;
    		}
    		return false;
    	}    
    

     待续

  • 相关阅读:
    Test
    占位2
    开坑纪念
    function 类型(函数定义)----读书总结
    css位元素 after
    算法-哈希表
    CF547D
    CF538H
    CF516D
    CF505E
  • 原文地址:https://www.cnblogs.com/lixiaolun/p/4684276.html
Copyright © 2011-2022 走看看