| | |
| | | import java.util.List; |
| | | |
| | | public class MainApp { |
| | | public static void main(String[] args) { |
| | | double startLat = 39.9042; |
| | | double startLon = 118.4074; |
| | | double endLat = 39.9042; |
| | | double endLon = 119.4074; |
| | | |
| | | double userLat = 39.9042; |
| | | double userLon = 116.4074; |
| | | |
| | | double radius = 50; // 单位:米 |
| | | int segments = 4; // 四段,共 5 个点 |
| | | try { |
| | | String routeJson = AmapApiClient.getDrivingRoute(startLat, startLon, endLat, endLon); |
| | | // 转化为json对象 |
| | | JSONObject jsonObject = JSONObject.parseObject(routeJson); |
| | | JSONObject route = jsonObject.getJSONObject("route"); |
| | | JSONArray paths = route.getJSONArray("paths"); |
| | | JSONObject o = (JSONObject)paths.get(0); |
| | | BigDecimal distance = o.getBigDecimal("distance"); |
| | | System.err.println( paths); |
| | | |
| | | List<double[]> fivePoints = PathParser.parseAndInterpolate(routeJson, segments,startLat, startLon, endLat, endLon); |
| | | |
| | | if (GeoChecker.isInAnyCircle(userLat, userLon, fivePoints, radius)) { |
| | | System.out.println("✅ 成功!您位于某个圆形电子围栏范围内。"); |
| | | } else { |
| | | System.out.println("❌ 失败!您不在任何圆形电子围栏范围内。"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |