首页 文章 精选 留言 我的

精选列表

搜索[java],共10000篇文章
优秀的个人博客,低调大师

java实现判断一个经纬度坐标是否在一个多边形内(经自己亲测)

1.在高德地图上绘制的多边形;经纬度逗号分隔格式;上面是用来方便存坐标的对象;下面是方法测试;直接复制代码即可运行 public class Point { private Double x; private Double y; public Point (Double x , Double y) { this.x = x; this.y = y; } public Double getX() { return x; } public void setX(Double x) { this.x = x; } public Double getY() { return y; } public void setY(Double y) { this.y = y; } } public class Test01 { public static void main(String[] args) { //114.331951,30.64091#114.341049,30.610185#114.331436,30.588058#114.312038,30.56393#114.293498,30.558609#114.267922,30.563784#114.231185,30.57945#114.212303,30.601616#114.235649,30.626878#114.280624,30.646818# Map [] map=new Map[]{}; Point[] ps = new Point[] { new Point(114.309914,30.599556),//114.309914,30.599556 new Point(114.295688,30.592879),//114.295688,30.592879 new Point(114.292812,30.587726), //114.292812,30.587726 new Point(114.292812,30.587726), //114.292812,30.587726 new Point(114.30058,30.580318),//114.30058,30.580318 new Point(114.303606,30.586959),//114.303606,30.586959 new Point(114.304534,30.594751),//114.304534,30.594751 new Point(114.30838,30.590131),//114.30838,30.590131 new Point(114.308651,30.584182),//114.308651,30.584182 new Point(114.304495,30.584015),//114.304495,30.584015 new Point(114.301301,30.578759),//114.301301,30.578759 new Point(114.309437,30.578528),//114.309437,30.578528 new Point(114.323282,30.592786)};//114.323282,30.592786 Point n1 = new Point(114.303217,30.583553); Point n2 = new Point(114.307336,30.597592); Point n3 = new Point(114.286565,30.590056); Point y1 = new Point(114.227342,30.587987); Point y2 = new Point(120.1866 , 30.2672); Point y4 = new Point(120.1869 , 30.2718); System.out.println( "n1:" + isPtInPoly(n1.getX() , n1.getY() , ps)); System.out.println( "n2:" + isPtInPoly(n2.getX() , n2.getY() , ps)); System.out.println( "n3:" + isPtInPoly(n3.getX() , n3.getY() , ps)); System.out.println( "y1:" + isPtInPoly(y1.getX() , y1.getY() , ps)); System.out.println( "y2:" + isPtInPoly(y2.getX() , y2.getY() , ps)); System.out.println( "y4:" + isPtInPoly(y4.getX() , y4.getY() , ps)); } public static boolean isPtInPoly (double ALon , double ALat , Point[] ps) { int iSum, iCount, iIndex; double dLon1 = 0, dLon2 = 0, dLat1 = 0, dLat2 = 0, dLon; if (ps.length < 3) { return false; } iSum = 0; iCount = ps.length; for (iIndex = 0; iIndex<iCount;iIndex++) { if (iIndex == iCount - 1) { dLon1 = ps[iIndex].getX(); dLat1 = ps[iIndex].getY(); dLon2 = ps[0].getX(); dLat2 = ps[0].getY(); } else { dLon1 = ps[iIndex].getX(); dLat1 = ps[iIndex].getY(); dLon2 = ps[iIndex + 1].getX(); dLat2 = ps[iIndex + 1].getY(); } // 以下语句判断A点是否在边的两端点的水平平行线之间,在则可能有交点,开始判断交点是否在左射线上 if (((ALat >= dLat1) && (ALat < dLat2)) || ((ALat >= dLat2) && (ALat < dLat1))) { if (Math.abs(dLat1 - dLat2) > 0) { //得到 A点向左射线与边的交点的x坐标: dLon = dLon1 - ((dLon1 - dLon2) * (dLat1 - ALat) ) / (dLat1 - dLat2); // 如果交点在A点左侧(说明是做射线与 边的交点),则射线与边的全部交点数加一: if (dLon < ALon) { iSum++; } } } } if ((iSum % 2) != 0) { return true; } return false; } }

优秀的个人博客,低调大师

【LeetCode-面试算法经典-Java实现】【111-Minimum Depth of Binary Tree(二叉树的最小深度)】

原题 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 题目大意 给定一棵两叉树求树的最小深度。 解题思路 遍历法,对整个树进行遍历,找出最小的深度。 代码实现 树结果定义 public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } 1 2 3 4 5 6 算法实现类 public class Solution { private int min = Integer.MAX_VALUE; // 记录树的最小深度 private int cur = 0; // i当前处理的树的尝试 public int minDepth(TreeNode root) { depth(root); return min; } /** * 计算树的深度 * * @param node 当前结点 */ private void depth(TreeNode node) { if (node == null) { min = cur; return; } cur++; // 当前处理的层次加1 // 如果是叶节点,并且路径比记录的最小还小 if (node.left == null && node.right == null && cur < min) { min = cur; // 更新最小值 } // 处理左子树 if (node.left != null) { depth(node.left); } // 处理右子树 if (node.right != null) { depth(node.right); } cur--; // 还原 } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 /** * 计算树的深度 * * @param node 当前结点 */ private void depth (TreeNode node) { if (node == null ) { min = cur; return ; } cur++; // 当前处理的层次加1 // 如果是叶节点,并且路径比记录的最小还小 if (node.left == null && node.right == null && cur < min) { min = cur; // 更新最小值 } // 处理左子树 if (node.left != null ) { depth(node.left); } // 处理右子树 if (node.right != null ) { depth(node.right); } cur--; // 还原 }}

优秀的个人博客,低调大师

java支付宝开发-异常-01-"sub_code":"isv.invalid-app-id","sub_msg":"无效的AppID参数"

一、现象 无论请求哪个接口都报这个错误 二、异常原因 后来检查了一下,发现是因为 我支付宝网关写错了。沙箱环境和正式环境 的支付宝网关不同,如下 //支付宝网关名-正式环境 //public static final String OPEN_API_DOMAIN="https://openapi.alipay.com/gateway.do"; //支付宝网关名-沙箱环境 public static final String OPEN_API_DOMAIN="https://openapi.alipaydev.com/gateway.do"; 二、参考资料 1.蚂蚁金服沙箱测试:无效的AppID参数 2.invalid-app-id(无效的AppID)参数问题自查方案

优秀的个人博客,低调大师

Java中,成员内部类的常见修饰符及应用 && 成员内部类不是静态的,访问的格式

成员内部类的常见修饰符及应用: private 为了保证数据的安全性 static 为了方便访问数据 注意:静态的内部类访问外部类的数据时,外部类的数据必须用静态修饰。 成员内部类不是静态的,访问的格式: 我的GitHub地址: https://github.com/heizemingjun 我的博客园地址: http://www.cnblogs.com/chenmingjun 我的蚂蚁笔记博客地址: http://blog.leanote.com/chenmingjun Copyright ©2018 黑泽明军 【转载文章务必保留出处和署名,谢谢!】

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册