Search in sources :

Example 6 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 7 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 8 with LatLngBounds

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

the class GeoJsonFeatureTest method testGetBoundingBox.

public void testGetBoundingBox() {
    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)

Example 9 with LatLngBounds

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

the class CustomMarkerClusteringDemoActivity method onClusterClick.

@Override
public boolean onClusterClick(Cluster<Person> cluster) {
    // Show a toast with some info when the cluster is clicked.
    String firstName = cluster.getItems().iterator().next().name;
    Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT).show();
    // Zoom in the cluster. Need to create LatLngBounds and including all the cluster items
    // inside of bounds, then animate to center of the bounds.
    // Create the builder to collect all essential cluster items for the bounds.
    LatLngBounds.Builder builder = LatLngBounds.builder();
    for (ClusterItem item : cluster.getItems()) {
        builder.include(item.getPosition());
    }
    // Get the LatLngBounds
    final LatLngBounds bounds = builder.build();
    // Animate camera to the bounds
    try {
        getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : ClusterItem(com.google.maps.android.clustering.ClusterItem) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds)

Aggregations

LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)9 LatLng (com.google.android.gms.maps.model.LatLng)5 HashMap (java.util.HashMap)2 Location (android.location.Location)1 Place (com.bubelov.coins.model.Place)1 AutocompletePrediction (com.google.android.gms.location.places.AutocompletePrediction)1 AutocompletePredictionBuffer (com.google.android.gms.location.places.AutocompletePredictionBuffer)1 PlaceLikelihood (com.google.android.gms.location.places.PlaceLikelihood)1 PlaceLikelihoodBuffer (com.google.android.gms.location.places.PlaceLikelihoodBuffer)1 ClusterItem (com.google.maps.android.clustering.ClusterItem)1 Geometry (com.google.maps.android.data.Geometry)1 KmlContainer (com.google.maps.android.data.kml.KmlContainer)1 KmlPlacemark (com.google.maps.android.data.kml.KmlPlacemark)1 KmlPolygon (com.google.maps.android.data.kml.KmlPolygon)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 Observable (rx.Observable)1 Action1 (rx.functions.Action1)1 Func2 (rx.functions.Func2)1 CompositeSubscription (rx.subscriptions.CompositeSubscription)1