java操作地理位置信息
2018-03-28 13:01
351 查看
1.计算矩形
package com.kensure.forecast.util; import java.util.HashMap; import java.util.Map; /** * * @author lcc * @time 2018-03-28 * @description * 处理有关地球地理信息的工具 */ public class EarthMapUtils { /** * * @param longitude 经度 * @param latitude 纬度 * @param distance 范围(米) * @description * x代表经度,y代表纬度 * 假设给了一个点O(x1,y1),求距离这个点300米的方块四个角的坐标A,B,C,D点的经度纬度 * * /|\ 纬度 Y * | * A -----------------|----------------B * | | | | * | | | | * | | 300米 | * | | | | * ------------------------|-----------------------------------》 经度 X * | |O(X1,Y1) | * | | | * | |------300米------ * | | | * | | | * |------------------|----------------D * C | * @return * Map<String, double[纬度,经度]> */ public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, double distance) { Map<String, double[]> squareMap = new HashMap<String, double[]>(); // 计算经度弧度,从弧度转换为角度 double dLongitude = 2 * (Math.asin(Math.sin(distance / (2 * 6378137)) / Math.cos(Math.toRadians(latitude)))); dLongitude = Math.toDegrees(dLongitude); 4000 // 计算纬度角度 double dLatitude = distance / 6378137; dLatitude = Math.toDegrees(dLatitude); // 正方形 double[] leftTopPoint = { latitude + dLatitude, longitude - dLongitude }; double[] rightTopPoint = { latitude + dLatitude, longitude + dLongitude }; double[] leftBottomPoint = { latitude - dLatitude,longitude - dLongitude }; double[] rightBottomPoint = { latitude - dLatitude,longitude + dLongitude }; squareMap.put("leftTopPoint", leftTopPoint); squareMap.put("rightTopPoint", rightTopPoint); squareMap.put("leftBottomPoint", leftBottomPoint); squareMap.put("rightBottomPoint", rightBottomPoint); System.out.println("==========("+leftTopPoint[1]+","+leftTopPoint[0]+")"+"===============("+rightTopPoint[1]+","+rightTopPoint[0]+")"); System.out.println("========== "); System.out.println("========== ("+longitude+","+latitude+") "); System.out.println("========== "); System.out.println("==========("+leftBottomPoint[1]+","+leftBottomPoint[0]+")"+"===============("+rightBottomPoint[1]+","+rightBottomPoint[0]+")"); return squareMap; } /** * 判断一个点(已知经度和纬度)是否在一个已知四个角经度和纬度的正方形内 * @param angle 正方形的四个角 * @param targetLongitude 要判断点是否在矩形内的经度 * @param targetLatitude 要判断点是否在矩形内的纬度 * @return */ public static boolean isHitAngle(Map<String, double[]> angle,double targetLongitude,double targetLatitude){ // 目标经度纬度 double x = targetLongitude; double y = targetLatitude; // 四个角 double[] aPoint = angle.get("leftTopPoint"); double[] bPoint = angle.get("rightTopPoint"); double[] cPoint = angle.get("leftBottomPoint"); double[] dPoint = angle.get("rightBottomPoint"); // 注意格式 【纬度】【经度】 boolean flag1 = aPoint[1] <= x && x <= bPoint[1];//经度在范围内 boolean flag2 = cPoint[0] <= y && y <= aPoint[0];//经度在范围内 boolean flag3 = flag1 && flag2;//给定的点在坐标内 if(flag3){ return true; } return false; } public static void main(String[] args) { Map<String, double[]> aa = EarthMapUtils.returnLLSquarePoint(119.21,-29.45,300); double[] aPoint = aa.get("leftTopPoint"); double[] bPoint = aa.get("rightTopPoint"); double[] cPoint = aa.get("leftBottomPoint"); double[] dPoint = aa.get("rightBottomPoint"); System.out.println("==========("+aPoint[1]+","+aPoint[0]+")"+"===============("+bPoint[1]+","+bPoint[0]+")"); System.out.println("========== "); System.out.println("========== (119.21,-29.45) "); System.out.println("========== "); System.out.println("==========("+cPoint[1]+","+cPoint[0]+")"+"===============("+dPoint[1]+","+dPoint[0]+")"); } }
相关文章推荐
- 从google的json接口获取地理位置信息的Java代码
- java脚本开发根据客户IP获取IP的具体地理位置信息
- java通过ip地址获取地理位置信息
- IP地址库解析——读取IP地址获得实际地理位置信息的java源码实现
- 项目源码--JAVA基于LBS地理位置信息应用的服务端
- Java获取客户端IP地址、MAC地址,根据IP获取地理位置信息代码
- 通过基站信息(LAC,CID)调用google的json接口获取地理位置信息的Java代码
- java 经纬度解析地址地理位置信息
- java使用jeids实现redis2.6的GEO(地理位置)数据结构的操作
- Redis,Geo,(地理位置信息操作)
- java根据ip地址从第三方接口获取详细的地理位置地域信息
- 调查发现超过一半的用户愿意透露地理位置获取优惠信息
- python使用在线API查询IP对应的地理位置信息实例
- Android中通过Exifinterface读取图片地理位置信息
- Java使用正则表达式及字符串操作,抽取网页信息
- Linux下显示IP地理位置信息的小工具-nali
- Java IO ——实例操作:单人信息管理程序
- [百度地图] 获取用户地理位置信息并解析成地址
- java获取代码调用位置信息
- 微信获取用户地理位置信息-微信jsapi接口