Java 中的地理围栏库

Geofence library in Java

你知道 java 开源地理围栏库(确定一个点是否在复杂多边形内),比如 Google 为 Android 播放服务吗?

尝试Google Maps Android API utility library: containsLocation

看看https://code.google.com/p/openmap/source/browse/src/openmap/com/bbn/openmap/geo/Intersection.java

public static boolean isPointInPolygon(Geo x, GeoArray poly)

使用开源库调用"utils"http://www.geotelematic.com/javadocs/org/opengts/util/package-summary.html

boolean isPointInside(GeoPoint gp) Returns true if the specified point is inside the polygon

。 包含在 OpenGts Proyect 中:http://www.opengts.org/

import org.opengts.util.GeoPoint;

import org.opengts.util.GeoPolygon;

使用此代码片段检查点是否在多边形内

    GeoPolygon fence = new GeoPolygon( // Define a Fence Polygon 
            new GeoPoint(-31.414547, -64.488178),
            new GeoPoint(-31.415579, -64.496261),
            new GeoPoint(-31.411513, -64.495720),
            new GeoPoint(-31.408726, -64.489549),
            new GeoPoint(-31.411898, -64.484406)
            );

    GeoPoint testgp1 = new GeoPoint(-31.411753, -64.489922);// Point1 inside
    GeoPoint testgp2 = new GeoPoint(-31.413962, -64.486445);// Point2 outside


    boolean inzone = fence.isPointInside(testgp1);
    System.out.println ("Point1 is inside of polygon= "+inzone);
    inzone = fence.isPointInside(testgp2);
    System.out.println ("Point2 is inside of polygon= "+inzone);

结果:

Point1 is inside of polygon= true
Point1 is inside of polygon= false