use of com.google.android.libraries.maps.model.LatLng in project android-samples by googlemaps.
the class MarkerCollisionDemoActivity method addMarkersToMap.
private void addMarkersToMap() {
MarkerOptions defaultMarkerOptions = new MarkerOptions();
// Add 100 markers to the map.
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
defaultMarkerOptions.position(new LatLng(SYDNEY.latitude + i, SYDNEY.longitude - j)).zIndex(i * 10 + j).title("zIndex:" + (i * 10 + j)).draggable(true);
if ((i + j) % 3 == 0) {
defaultMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY);
} else if ((i + j) % 3 == 1) {
defaultMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL);
} else {
defaultMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
defaultMarkerOptions.collisionBehavior(Marker.CollisionBehavior.REQUIRED);
}
map.addMarker(defaultMarkerOptions);
}
}
}
use of com.google.android.libraries.maps.model.LatLng in project android-samples by googlemaps.
the class PolylineDemoActivity method onMapReady.
@Override
public void onMapReady(GoogleMap map) {
// For accessibility mode. Ideally this string would be localised.
map.setContentDescription("Google Map with polylines.");
// Non-loop polyline that goes past Australian cities. Added before sydneyPolyline and would
// normally be underneath, but increase Z-Index so that this line is on top.
australiaPolyline = map.addPolyline(new PolylineOptions().add(PERTH, ADELAIDE, SYDNEY, MELBOURNE).pattern(Arrays.asList(new Dot(), new Gap(20.0f))).color(Color.MAGENTA).zIndex(1));
// Geodesic polyline that goes around the world.
worldPolyline = map.addPolyline(new PolylineOptions().add(LONDON, AUCKLAND, LOS_ANGELES, NEW_YORK, LONDON).width(5).color(Color.BLUE).geodesic(true).clickable(true));
// Loop polyline centered at Sydney.
int radius = 4;
sydneyPolyline = map.addPolyline(new PolylineOptions().add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)).add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude - radius)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude - radius)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude)).add(new LatLng(SYDNEY.latitude - radius, SYDNEY.longitude + radius)).add(new LatLng(SYDNEY.latitude + radius, SYDNEY.longitude + radius)).pattern(Arrays.asList(new Dash(45.0f), new Gap(10.0f))).color(Color.RED).width(5).clickable(true));
// Create Melbourne polyline to show layering of polylines with same Z-Index. This is added
// second so it will be layered on top of the Sydney polyline (both have Z-Index == 0).
melbournePolyline = map.addPolyline(new PolylineOptions().add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)).add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude - radius)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude - radius)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude)).add(new LatLng(MELBOURNE.latitude - radius, MELBOURNE.longitude + radius)).add(new LatLng(MELBOURNE.latitude + radius, MELBOURNE.longitude + radius)).color(Color.GREEN).width(5).clickable(true));
map.moveCamera(CameraUpdateFactory.newLatLng(SYDNEY));
selectedPolyline = australiaPolyline;
polylineRadio.check(R.id.polyline_radio_australia);
pager.addOnPageChangeListener(this);
polylineRadio.setOnCheckedChangeListener(this);
map.setOnPolylineClickListener(this);
}
use of com.google.android.libraries.maps.model.LatLng in project android-samples by googlemaps.
the class MarkerDemoActivity method addMarkersToMap.
private void addMarkersToMap() {
// Uses a colored icon.
mBrisbane = mMap.addMarker(new MarkerOptions().position(BRISBANE).title("Brisbane").snippet("Population: 2,074,200").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
// Uses a custom icon with the info window popping out of the center of the icon.
mSydney = mMap.addMarker(new MarkerOptions().position(SYDNEY).title("Sydney").snippet("Population: 4,627,300").icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)).infoWindowAnchor(0.5f, 0.5f));
// Creates a draggable marker. Long press to drag.
mMelbourne = mMap.addMarker(new MarkerOptions().position(MELBOURNE).title("Melbourne").snippet("Population: 4,137,400").draggable(true));
// Place four markers on top of each other with differing z-indexes.
mDarwin1 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 1").snippet("z-index 1").zIndex(1));
mDarwin2 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 2").snippet("z-index 2").zIndex(2));
mDarwin3 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 3").snippet("z-index 3").zIndex(3));
mDarwin4 = mMap.addMarker(new MarkerOptions().position(DARWIN).title("Darwin Marker 4").snippet("z-index 4").zIndex(4));
// A few more markers for good measure.
mPerth = mMap.addMarker(new MarkerOptions().position(PERTH).title("Perth").snippet("Population: 1,738,800"));
mAdelaide = mMap.addMarker(new MarkerOptions().position(ADELAIDE).title("Adelaide").snippet("Population: 1,213,000"));
// Vector drawable resource as a marker icon.
mMap.addMarker(new MarkerOptions().position(ALICE_SPRINGS).icon(vectorToBitmap(R.drawable.ic_android, Color.parseColor("#A4C639"))).title("Alice Springs"));
// Creates a marker rainbow demonstrating how to create default marker icons of different
// hues (colors).
float rotation = mRotationBar.getProgress();
boolean flat = mFlatBox.isChecked();
int numMarkersInRainbow = 12;
for (int i = 0; i < numMarkersInRainbow; i++) {
Marker marker = mMap.addMarker(new MarkerOptions().position(new LatLng(-30 + 10 * Math.sin(i * Math.PI / (numMarkersInRainbow - 1)), 135 - 10 * Math.cos(i * Math.PI / (numMarkersInRainbow - 1)))).title("Marker " + i).icon(BitmapDescriptorFactory.defaultMarker(i * 360 / numMarkersInRainbow)).flat(flat).rotation(rotation));
mMarkerRainbow.add(marker);
}
}
use of com.google.android.libraries.maps.model.LatLng in project android-samples by googlemaps.
the class CameraDemoActivity method addCameraTargetToPath.
// [START_EXCLUDE silent]
private void addCameraTargetToPath() {
LatLng target = map.getCameraPosition().target;
currPolylineOptions.add(target);
}
use of com.google.android.libraries.maps.model.LatLng in project android-samples by googlemaps.
the class CircleDemoActivity method onMapLongClick.
@Override
public void onMapLongClick(LatLng point) {
// We know the center, let's place the outline at a point 3/4 along the view.
View view = getSupportFragmentManager().findFragmentById(R.id.map).getView();
LatLng radiusLatLng = map.getProjection().fromScreenLocation(new Point(view.getHeight() * 3 / 4, view.getWidth() * 3 / 4));
// Create the circle.
DraggableCircle circle = new DraggableCircle(point, toRadiusMeters(point, radiusLatLng));
circles.add(circle);
}
Aggregations