com.google.maps.android.PolyUtil Java Examples

The following examples show how to use com.google.maps.android.PolyUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Is the point of the polygon
 *
 * @param point     point
 * @param polygon   polygon
 * @param geodesic  geodesic check flag
 * @param tolerance distance tolerance
 * @return true if on the polygon
 */
public static boolean isPointOnPolygon(LatLng point, PolygonOptions polygon, boolean geodesic, double tolerance) {

    boolean onPolygon = PolyUtil.containsLocation(point, polygon.getPoints(), geodesic) ||
            PolyUtil.isLocationOnEdge(point, polygon.getPoints(), geodesic, tolerance);

    if (onPolygon) {
        for (List<LatLng> hole : polygon.getHoles()) {
            if (PolyUtil.containsLocation(point, hole, geodesic)) {
                onPolygon = false;
                break;
            }
        }
    }

    return onPolygon;
}
 
Example #2
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Close the polygon ring (exterior or hole) points if needed
 *
 * @param points ring points
 * @since 1.3.2
 */
public void closePolygonRing(List<LatLng> points) {
    if (!PolyUtil.isClosedPolygon(points)) {
        LatLng first = points.get(0);
        points.add(new LatLng(first.latitude, first.longitude));
    }
}
 
Example #3
Source File: PolyDecodeDemoActivity.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
@Override
protected void startDemo(boolean isRestore) {
    List<LatLng> decodedPath = PolyUtil.decode(LINE);

    getMap().addPolyline(new PolylineOptions().addAll(decodedPath));

    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 12));
    }
}
 
Example #4
Source File: BusManager.java    From NYU-BusTracker-Android with Apache License 2.0 5 votes vote down vote up
public static void parseSegments(JSONObject segmentsJSON) throws JSONException {
    JSONObject jSegments = new JSONObject();
    if (segmentsJSON != null) jSegments = segmentsJSON.getJSONObject("data");
    if (jSegments != null) {
        for (Route r : routes) {
            if (BuildConfig.DEBUG)
                Log.v(MainActivity.REFACTOR_LOG_TAG, "Parsing segments for " + r + " (" + r.getSegmentIDs() + ")");
            for (String seg : r.getSegmentIDs()) {
                if (jSegments.has(seg)) {
                    r.getSegments().add(new PolylineOptions().addAll(PolyUtil.decode(jSegments.getString(seg))));
                }
            }
        }
    }
}
 
Example #5
Source File: RoutePolyline.java    From GoogleDirectionLibrary with Apache License 2.0 4 votes vote down vote up
public List<LatLng> getPointList() {
    return PolyUtil.decode(rawPointList);
}
 
Example #6
Source File: PolylineActivity.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
@Override
protected void initMapSettings() {
    List<LatLng> decodedPath = PolyUtil.decode(polyline);

    mGoogleMap.addPolyline(new PolylineOptions().addAll(decodedPath));
}
 
Example #7
Source File: PolySimplifyDemoActivity.java    From android-maps-utils with Apache License 2.0 4 votes vote down vote up
@Override
protected void startDemo(boolean isRestore) {
    GoogleMap map = getMap();

    // Original line
    List<LatLng> line = PolyUtil.decode(LINE);
    map.addPolyline(new PolylineOptions()
            .addAll(line)
            .color(Color.BLACK));

    if (!isRestore) {
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
    }

    List<LatLng> simplifiedLine;

    /*
     * Simplified lines - increasing the tolerance will result in fewer points in the simplified
     * line
     */
    double tolerance = 5; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.RED - ALPHA_ADJUSTMENT));

    tolerance = 20; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.GREEN - ALPHA_ADJUSTMENT));

    tolerance = 50; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.MAGENTA - ALPHA_ADJUSTMENT));

    tolerance = 500; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.YELLOW - ALPHA_ADJUSTMENT));

    tolerance = 1000; // meters
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    map.addPolyline(new PolylineOptions()
            .addAll(simplifiedLine)
            .color(Color.BLUE - ALPHA_ADJUSTMENT));


    // Triangle polygon - the polygon should be closed
    ArrayList<LatLng> triangle = new ArrayList<>();
    triangle.add(new LatLng(28.06025,-82.41030));  // Should match last point
    triangle.add(new LatLng(28.06129,-82.40945));
    triangle.add(new LatLng(28.06206,-82.40917));
    triangle.add(new LatLng(28.06125,-82.40850));
    triangle.add(new LatLng(28.06035,-82.40834));
    triangle.add(new LatLng(28.06038, -82.40924));
    triangle.add(new LatLng(28.06025,-82.41030));  // Should match first point

    map.addPolygon(new PolygonOptions()
            .addAll(triangle)
            .fillColor(Color.BLUE - ALPHA_ADJUSTMENT)
            .strokeColor(Color.BLUE)
            .strokeWidth(5));

    // Simplified triangle polygon
    tolerance = 88; // meters
    List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
    map.addPolygon(new PolygonOptions()
            .addAll(simplifiedTriangle)
            .fillColor(Color.YELLOW - ALPHA_ADJUSTMENT)
            .strokeColor(Color.YELLOW)
            .strokeWidth(5));

    // Oval polygon - the polygon should be closed
    List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
    map.addPolygon(new PolygonOptions()
            .addAll(oval)
            .fillColor(Color.BLUE - ALPHA_ADJUSTMENT)
            .strokeColor(Color.BLUE)
            .strokeWidth(5));

    // Simplified oval polygon
    tolerance = 10; // meters
    List simplifiedOval= PolyUtil.simplify(oval, tolerance);
    map.addPolygon(new PolygonOptions()
            .addAll(simplifiedOval)
            .fillColor(Color.YELLOW - ALPHA_ADJUSTMENT)
            .strokeColor(Color.YELLOW)
            .strokeWidth(5));
}
 
Example #8
Source File: MapPolylineObservation.java    From mage-android with Apache License 2.0 3 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @Override
 */
public boolean pointIsOnShape(LatLng latLng, double tolerance) {

    boolean onShape = PolyUtil.isLocationOnPath(latLng, polyline.getPoints(), polyline.isGeodesic(), tolerance);

    return onShape;
}
 
Example #9
Source File: MapPolygonObservation.java    From mage-android with Apache License 2.0 3 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @Override
 */
public boolean pointIsOnShape(LatLng latLng, double tolerance) {

    boolean onShape = PolyUtil.containsLocation(latLng, polygon.getPoints(), polygon.isGeodesic());

    return onShape;
}
 
Example #10
Source File: MapUtils.java    From geopackage-android-map with MIT License 2 votes vote down vote up
/**
 * Is the point on the polyline
 *
 * @param point     point
 * @param polyline  polyline
 * @param geodesic  geodesic check flag
 * @param tolerance distance tolerance
 * @return true if on the line
 */
public static boolean isPointOnPolyline(LatLng point, PolylineOptions polyline, boolean geodesic, double tolerance) {
    return PolyUtil.isLocationOnPath(point, polyline.getPoints(), geodesic, tolerance);
}