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);
}
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);
}
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());
}
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;
}
Aggregations