use of com.google.android.libraries.maps.model.MarkerOptions 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.MarkerOptions in project android-samples by googlemaps.
the class LiteDemoActivity method addMarkers.
/**
* Add Markers with default info windows to the map.
*/
private void addMarkers() {
map.addMarker(new MarkerOptions().position(BRISBANE).title("Brisbane"));
map.addMarker(new MarkerOptions().position(MELBOURNE).title("Melbourne").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
map.addMarker(new MarkerOptions().position(SYDNEY).title("Sydney").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
map.addMarker(new MarkerOptions().position(ADELAIDE).title("Adelaide").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW)));
map.addMarker(new MarkerOptions().position(PERTH).title("Perth").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)));
}
use of com.google.android.libraries.maps.model.MarkerOptions in project android-samples by googlemaps.
the class SplitStreetViewPanoramaAndMapDemoActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.split_street_view_panorama_and_map_demo);
final LatLng markerPosition;
if (savedInstanceState == null) {
markerPosition = SYDNEY;
} else {
markerPosition = savedInstanceState.getParcelable(MARKER_POSITION_KEY);
}
SupportStreetViewPanoramaFragment streetViewPanoramaFragment = (SupportStreetViewPanoramaFragment) getSupportFragmentManager().findFragmentById(R.id.streetviewpanorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(new OnStreetViewPanoramaReadyCallback() {
@Override
public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
streetViewPanorama = panorama;
streetViewPanorama.setOnStreetViewPanoramaChangeListener(SplitStreetViewPanoramaAndMapDemoActivity.this);
// its state.
if (savedInstanceState == null) {
streetViewPanorama.setPosition(SYDNEY);
}
}
});
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap map) {
map.setOnMarkerDragListener(SplitStreetViewPanoramaAndMapDemoActivity.this);
// Creates a draggable marker. Long press to drag.
marker = map.addMarker(new MarkerOptions().position(markerPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.pegman)).draggable(true));
}
});
}
use of com.google.android.libraries.maps.model.MarkerOptions in project android-samples by googlemaps.
the class TagsDemoActivity method addObjectsToMap.
private void addObjectsToMap() {
// A circle centered on Adelaide.
mAdelaideCircle = mMap.addCircle(new CircleOptions().center(ADELAIDE).radius(500000).fillColor(Color.argb(150, 66, 173, 244)).strokeColor(Color.rgb(66, 173, 244)).clickable(true));
mAdelaideCircle.setTag(new CustomTag("Adelaide circle"));
// A ground overlay at Sydney.
mSydneyGroundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions().image(BitmapDescriptorFactory.fromResource(R.drawable.harbour_bridge)).position(SYDNEY, 700000).clickable(true));
mSydneyGroundOverlay.setTag(new CustomTag("Sydney ground overlay"));
// A marker at Hobart.
mHobartMarker = mMap.addMarker(new MarkerOptions().position(HOBART));
mHobartMarker.setTag(new CustomTag("Hobart marker"));
// A polygon centered at Darwin.
mDarwinPolygon = mMap.addPolygon(new PolygonOptions().add(new LatLng(DARWIN.latitude + 3, DARWIN.longitude - 3), new LatLng(DARWIN.latitude + 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude + 3), new LatLng(DARWIN.latitude - 3, DARWIN.longitude - 3)).fillColor(Color.argb(150, 34, 173, 24)).strokeColor(Color.rgb(34, 173, 24)).clickable(true));
mDarwinPolygon.setTag(new CustomTag("Darwin polygon"));
// A polyline from Perth to Brisbane.
mPolyline = mMap.addPolyline(new PolylineOptions().add(PERTH, BRISBANE).color(Color.rgb(103, 24, 173)).width(30).clickable(true));
mPolyline.setTag(new CustomTag("Perth to Brisbane polyline"));
}
use of com.google.android.libraries.maps.model.MarkerOptions in project android-maps-utils by googlemaps.
the class MultiLayerDemoActivity method startDemo.
@Override
protected void startDemo(boolean isRestore) {
if (!isRestore) {
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.403186, -0.126446), 10));
}
// Shared object managers - used to support multiple layer types on the map simultaneously
MarkerManager markerManager = new MarkerManager(getMap());
GroundOverlayManager groundOverlayManager = new GroundOverlayManager(getMap());
PolygonManager polygonManager = new PolygonManager(getMap());
PolylineManager polylineManager = new PolylineManager(getMap());
// Add clustering
ClusterManager<MyItem> clusterManager = new ClusterManager<>(this, getMap(), markerManager);
getMap().setOnCameraIdleListener(clusterManager);
addClusterItems(clusterManager);
// Add GeoJSON from resource
try {
// GeoJSON polyline
GeoJsonLayer geoJsonLineLayer = new GeoJsonLayer(getMap(), R.raw.south_london_line_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
// Make the line red
GeoJsonLineStringStyle geoJsonLineStringStyle = new GeoJsonLineStringStyle();
geoJsonLineStringStyle.setColor(Color.RED);
for (GeoJsonFeature f : geoJsonLineLayer.getFeatures()) {
f.setLineStringStyle(geoJsonLineStringStyle);
}
geoJsonLineLayer.addLayerToMap();
geoJsonLineLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature -> Toast.makeText(MultiLayerDemoActivity.this, "GeoJSON polyline clicked: " + feature.getProperty("title"), Toast.LENGTH_SHORT).show());
// GeoJSON polygon
GeoJsonLayer geoJsonPolygonLayer = new GeoJsonLayer(getMap(), R.raw.south_london_square_geojson, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
// Fill it with red
GeoJsonPolygonStyle geoJsonPolygonStyle = new GeoJsonPolygonStyle();
geoJsonPolygonStyle.setFillColor(Color.RED);
for (GeoJsonFeature f : geoJsonPolygonLayer.getFeatures()) {
f.setPolygonStyle(geoJsonPolygonStyle);
}
geoJsonPolygonLayer.addLayerToMap();
geoJsonPolygonLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature -> Toast.makeText(MultiLayerDemoActivity.this, "GeoJSON polygon clicked: " + feature.getProperty("title"), Toast.LENGTH_SHORT).show());
} catch (IOException e) {
Log.e(TAG, "GeoJSON file could not be read");
} catch (JSONException e) {
Log.e(TAG, "GeoJSON file could not be converted to a JSONObject");
}
// Add KMLs from resources
try {
// KML Polyline
KmlLayer kmlPolylineLayer = new KmlLayer(getMap(), R.raw.south_london_line_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
kmlPolylineLayer.addLayerToMap();
kmlPolylineLayer.setOnFeatureClickListener(feature -> Toast.makeText(MultiLayerDemoActivity.this, "KML polyline clicked: " + feature.getProperty("name"), Toast.LENGTH_SHORT).show());
// KML Polygon
KmlLayer kmlPolygonLayer = new KmlLayer(getMap(), R.raw.south_london_square_kml, this, markerManager, polygonManager, polylineManager, groundOverlayManager, null);
kmlPolygonLayer.addLayerToMap();
kmlPolygonLayer.setOnFeatureClickListener(feature -> Toast.makeText(MultiLayerDemoActivity.this, "KML polygon clicked: " + feature.getProperty("name"), Toast.LENGTH_SHORT).show());
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// Unclustered marker - instead of adding to the map directly, use the MarkerManager
MarkerManager.Collection markerCollection = markerManager.newCollection();
markerCollection.addMarker(new MarkerOptions().position(new LatLng(51.150000, -0.150032)).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)).title("Unclustered marker"));
markerCollection.setOnMarkerClickListener(marker -> {
Toast.makeText(MultiLayerDemoActivity.this, "Marker clicked: " + marker.getTitle(), Toast.LENGTH_SHORT).show();
return false;
});
}
Aggregations