Search in sources :

Example 31 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.

the class GeoJsonParser method parseFeature.

/**
 * Parses a single GeoJSON feature which contains a geometry and properties member both of
 * which can be null. Also parses the bounding box and id members of the feature if they exist.
 *
 * @param geoJsonFeature feature to parse
 * @return GeoJsonFeature object
 */
private static GeoJsonFeature parseFeature(JSONObject geoJsonFeature) {
    String id = null;
    LatLngBounds boundingBox = null;
    Geometry geometry = null;
    HashMap<String, String> properties = new HashMap<String, String>();
    try {
        if (geoJsonFeature.has(FEATURE_ID)) {
            id = geoJsonFeature.getString(FEATURE_ID);
        }
        if (geoJsonFeature.has(BOUNDING_BOX)) {
            boundingBox = parseBoundingBox(geoJsonFeature.getJSONArray(BOUNDING_BOX));
        }
        if (geoJsonFeature.has(FEATURE_GEOMETRY) && !geoJsonFeature.isNull(FEATURE_GEOMETRY)) {
            geometry = parseGeometry(geoJsonFeature.getJSONObject(FEATURE_GEOMETRY));
        }
        if (geoJsonFeature.has(PROPERTIES) && !geoJsonFeature.isNull(PROPERTIES)) {
            properties = parseProperties(geoJsonFeature.getJSONObject("properties"));
        }
    } catch (JSONException e) {
        Log.w(LOG_TAG, "Feature could not be successfully parsed " + geoJsonFeature.toString());
        return null;
    }
    return new GeoJsonFeature(geometry, id, properties, boundingBox);
}
Also used : Geometry(com.google.maps.android.data.Geometry) HashMap(java.util.HashMap) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) JSONException(org.json.JSONException)

Example 32 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.

the class KmlFeatureParser method createLatLngBounds.

/**
 * Given a set of four latLng coordinates, creates a LatLng Bound
 *
 * @param north North coordinate of the bounding box
 * @param south South coordinate of the bounding box
 * @param east  East coordinate of the bounding box
 * @param west  West coordinate of the bounding box
 */
private static LatLngBounds createLatLngBounds(Double north, Double south, Double east, Double west) {
    LatLng southWest = new LatLng(south, west);
    LatLng northEast = new LatLng(north, east);
    return new LatLngBounds(southWest, northEast);
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng)

Example 33 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.

the class KmlFeatureParser method createGroundOverlay.

/**
 * Creates a new GroundOverlay object (created if a GroundOverlay tag is read by the
 * XmlPullParser) and assigns specific elements read from the parser to the GroundOverlay
 */
/* package */
static KmlGroundOverlay createGroundOverlay(XmlPullParser parser) throws IOException, XmlPullParserException {
    float drawOrder = 0.0f;
    float rotation = 0.0f;
    int visibility = 1;
    String imageUrl = null;
    LatLngBounds latLonBox;
    HashMap<String, String> properties = new HashMap<String, String>();
    HashMap<String, Double> compassPoints = new HashMap<String, Double>();
    int eventType = parser.getEventType();
    while (!(eventType == END_TAG && parser.getName().equals("GroundOverlay"))) {
        if (eventType == START_TAG) {
            if (parser.getName().equals("Icon")) {
                imageUrl = getImageUrl(parser);
            } else if (parser.getName().equals("drawOrder")) {
                drawOrder = Float.parseFloat(parser.nextText());
            } else if (parser.getName().equals("visibility")) {
                visibility = Integer.parseInt(parser.nextText());
            } else if (parser.getName().equals("ExtendedData")) {
                properties.putAll(setExtendedDataProperties(parser));
            } else if (parser.getName().equals("rotation")) {
                rotation = getRotation(parser);
            } else if (parser.getName().matches(PROPERTY_REGEX) || parser.getName().equals("color")) {
                properties.put(parser.getName(), parser.nextText());
            } else if (parser.getName().matches(COMPASS_REGEX)) {
                compassPoints.put(parser.getName(), Double.parseDouble(parser.nextText()));
            }
        }
        eventType = parser.next();
    }
    latLonBox = createLatLngBounds(compassPoints.get("north"), compassPoints.get("south"), compassPoints.get("east"), compassPoints.get("west"));
    return new KmlGroundOverlay(imageUrl, latLonBox, drawOrder, visibility, properties, rotation);
}
Also used : HashMap(java.util.HashMap) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds)

Example 34 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project android-maps-utils by googlemaps.

the class GeoJsonFeatureTest method testGetBoundingBox.

@Test
public void testGetBoundingBox() {
    GeoJsonFeature feature = new GeoJsonFeature(null, null, null, null);
    assertNull(feature.getBoundingBox());
    LatLngBounds boundingBox = new LatLngBounds(new LatLng(-20, -20), new LatLng(50, 50));
    feature = new GeoJsonFeature(null, null, null, boundingBox);
    assertEquals(boundingBox, feature.getBoundingBox());
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng) Test(org.junit.Test)

Example 35 with LatLngBounds

use of com.google.android.gms.maps.model.LatLngBounds in project collect by opendatakit.

the class GoogleMapFragment method expandBounds.

private LatLngBounds expandBounds(LatLngBounds bounds, double factor) {
    double north = bounds.northeast.latitude;
    double south = bounds.southwest.latitude;
    double latCenter = (north + south) / 2;
    double latRadius = ((north - south) / 2) * factor;
    north = Math.min(90, latCenter + latRadius);
    south = Math.max(-90, latCenter - latRadius);
    double east = bounds.northeast.longitude;
    double west = bounds.southwest.longitude;
    while (east < west) {
        east += 360;
    }
    double lonCenter = (east + west) / 2;
    double lonRadius = Math.min(180 - 1e-6, ((east - west) / 2) * factor);
    east = lonCenter + lonRadius;
    west = lonCenter - lonRadius;
    return new LatLngBounds(new LatLng(south, west), new LatLng(north, east));
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) LatLng(com.google.android.gms.maps.model.LatLng)

Aggregations

LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)42 LatLng (com.google.android.gms.maps.model.LatLng)27 CameraUpdate (com.google.android.gms.maps.CameraUpdate)11 Marker (com.google.android.gms.maps.model.Marker)6 Intent (android.content.Intent)5 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)5 ArrayList (java.util.ArrayList)5 View (android.view.View)4 JSONException (org.json.JSONException)4 Handler (android.os.Handler)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 AutocompletePrediction (com.google.android.gms.location.places.AutocompletePrediction)3 AutocompletePredictionBuffer (com.google.android.gms.location.places.AutocompletePredictionBuffer)3 GoogleMap (com.google.android.gms.maps.GoogleMap)3 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)3 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 SuppressLint (android.annotation.SuppressLint)2 Cursor (android.database.Cursor)2