Search in sources :

Example 6 with MarkerOptions

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);
    }
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) Marker(com.google.android.libraries.maps.model.Marker) LatLng(com.google.android.libraries.maps.model.LatLng)

Example 7 with MarkerOptions

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)));
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions)

Example 8 with MarkerOptions

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));
        }
    });
}
Also used : SupportMapFragment(com.google.android.libraries.maps.SupportMapFragment) StreetViewPanorama(com.google.android.libraries.maps.StreetViewPanorama) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) OnStreetViewPanoramaReadyCallback(com.google.android.libraries.maps.OnStreetViewPanoramaReadyCallback) GoogleMap(com.google.android.libraries.maps.GoogleMap) OnMapReadyCallback(com.google.android.libraries.maps.OnMapReadyCallback) LatLng(com.google.android.libraries.maps.model.LatLng) SupportStreetViewPanoramaFragment(com.google.android.libraries.maps.SupportStreetViewPanoramaFragment)

Example 9 with MarkerOptions

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"));
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) CircleOptions(com.google.android.libraries.maps.model.CircleOptions) GroundOverlayOptions(com.google.android.libraries.maps.model.GroundOverlayOptions) PolygonOptions(com.google.android.libraries.maps.model.PolygonOptions) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Example 10 with MarkerOptions

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;
    });
}
Also used : GeoJsonFeature(com.google.maps.android.data.geojson.GeoJsonFeature) KmlLayer(com.google.maps.android.data.kml.KmlLayer) BitmapDescriptorFactory(com.google.android.libraries.maps.model.BitmapDescriptorFactory) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) LatLng(com.google.android.libraries.maps.model.LatLng) IOException(java.io.IOException) ClusterManager(com.google.maps.android.clustering.ClusterManager) PolylineManager(com.google.maps.android.collections.PolylineManager) Color(android.graphics.Color) GeoJsonFeature(com.google.maps.android.data.geojson.GeoJsonFeature) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) MarkerManager(com.google.maps.android.collections.MarkerManager) JSONException(org.json.JSONException) List(java.util.List) Toast(android.widget.Toast) CameraUpdateFactory(com.google.android.libraries.maps.CameraUpdateFactory) GeoJsonLayer(com.google.maps.android.data.geojson.GeoJsonLayer) MyItem(com.google.maps.android.utils.demo.model.MyItem) GeoJsonPolygonStyle(com.google.maps.android.data.geojson.GeoJsonPolygonStyle) GroundOverlayManager(com.google.maps.android.collections.GroundOverlayManager) GeoJsonLineStringStyle(com.google.maps.android.data.geojson.GeoJsonLineStringStyle) Log(android.util.Log) PolygonManager(com.google.maps.android.collections.PolygonManager) InputStream(java.io.InputStream) KmlLayer(com.google.maps.android.data.kml.KmlLayer) GeoJsonLineStringStyle(com.google.maps.android.data.geojson.GeoJsonLineStringStyle) GroundOverlayManager(com.google.maps.android.collections.GroundOverlayManager) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) GeoJsonPolygonStyle(com.google.maps.android.data.geojson.GeoJsonPolygonStyle) JSONException(org.json.JSONException) IOException(java.io.IOException) MyItem(com.google.maps.android.utils.demo.model.MyItem) GeoJsonLayer(com.google.maps.android.data.geojson.GeoJsonLayer) PolygonManager(com.google.maps.android.collections.PolygonManager) PolylineManager(com.google.maps.android.collections.PolylineManager) MarkerManager(com.google.maps.android.collections.MarkerManager) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) LatLng(com.google.android.libraries.maps.model.LatLng) ClusterManager(com.google.maps.android.clustering.ClusterManager)

Aggregations

MarkerOptions (com.google.android.libraries.maps.model.MarkerOptions)10 LatLng (com.google.android.libraries.maps.model.LatLng)7 Marker (com.google.android.libraries.maps.model.Marker)2 PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)2 Bitmap (android.graphics.Bitmap)1 Color (android.graphics.Color)1 Log (android.util.Log)1 Toast (android.widget.Toast)1 JSObject (com.getcapacitor.JSObject)1 PluginMethod (com.getcapacitor.PluginMethod)1 CameraUpdateFactory (com.google.android.libraries.maps.CameraUpdateFactory)1 GoogleMap (com.google.android.libraries.maps.GoogleMap)1 OnCameraIdleListener (com.google.android.libraries.maps.GoogleMap.OnCameraIdleListener)1 OnMapReadyCallback (com.google.android.libraries.maps.OnMapReadyCallback)1 OnStreetViewPanoramaReadyCallback (com.google.android.libraries.maps.OnStreetViewPanoramaReadyCallback)1 StreetViewPanorama (com.google.android.libraries.maps.StreetViewPanorama)1 SupportMapFragment (com.google.android.libraries.maps.SupportMapFragment)1 SupportStreetViewPanoramaFragment (com.google.android.libraries.maps.SupportStreetViewPanoramaFragment)1 BitmapDescriptorFactory (com.google.android.libraries.maps.model.BitmapDescriptorFactory)1 CircleOptions (com.google.android.libraries.maps.model.CircleOptions)1