Search in sources :

Example 1 with MarkerOptions

use of com.google.android.libraries.maps.model.MarkerOptions in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method addMarker.

@PluginMethod()
public void addMarker(final PluginCall call) {
    final Double latitude = call.getDouble("latitude", 0d);
    final Double longitude = call.getDouble("longitude", 0d);
    final Float opacity = call.getFloat("opacity", 1.0f);
    final String title = call.getString("title", "");
    final String snippet = call.getString("snippet", "");
    final Boolean isFlat = call.getBoolean("isFlat", true);
    final JSObject metadata = call.getObject("metadata");
    final String url = call.getString("iconUrl", "");
    final Boolean draggable = call.getBoolean("draggable", false);
    if (googleMap == null) {
        call.reject("Map is not ready");
        return;
    }
    Bitmap imageBitmap = getBitmapFromURL(url);
    getBridge().getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            LatLng latLng = new LatLng(latitude, longitude);
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.alpha(opacity);
            markerOptions.title(title);
            markerOptions.snippet(snippet);
            markerOptions.flat(isFlat);
            markerOptions.draggable(draggable);
            if (imageBitmap != null) {
                markerOptions.icon(BitmapDescriptorFactory.fromBitmap(imageBitmap));
            }
            Marker marker = googleMap.addMarker(markerOptions);
            // set metadata to marker
            marker.setTag(metadata);
            // get auto-generated id of the just added marker,
            // put this marker into a hashmap with the corresponding id,
            // so we can retrieve the marker by id later on
            mHashMap.put(marker.getId(), marker);
            // initialize JSObject to return when resolving this call
            JSObject result = new JSObject();
            JSObject markerResult = new JSObject();
            // get marker specific values
            markerResult.put("id", marker.getId());
            result.put("marker", markerResult);
            call.resolve(result);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) JSObject(com.getcapacitor.JSObject) LatLng(com.google.android.libraries.maps.model.LatLng) Marker(com.google.android.libraries.maps.model.Marker) PluginMethod(com.getcapacitor.PluginMethod)

Example 2 with MarkerOptions

use of com.google.android.libraries.maps.model.MarkerOptions in project android-maps-utils by googlemaps.

the class IconGeneratorDemoActivity method addIcon.

private void addIcon(IconGenerator iconFactory, CharSequence text, LatLng position) {
    MarkerOptions markerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(text))).position(position).anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());
    getMap().addMarker(markerOptions);
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions)

Example 3 with MarkerOptions

use of com.google.android.libraries.maps.model.MarkerOptions in project android-maps-utils by googlemaps.

the class DistanceDemoActivity method startDemo.

@Override
protected void startDemo(boolean isRestore) {
    mTextView = findViewById(R.id.textView);
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 10));
    }
    getMap().setOnMarkerDragListener(this);
    mMarkerA = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.9046, 151.155)).draggable(true));
    mMarkerB = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.8291, 151.248)).draggable(true));
    mPolyline = getMap().addPolyline(new PolylineOptions().geodesic(true));
    Toast.makeText(this, "Drag the markers!", Toast.LENGTH_LONG).show();
    showDistance();
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

Example 4 with MarkerOptions

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

Example 5 with MarkerOptions

use of com.google.android.libraries.maps.model.MarkerOptions in project android-samples by googlemaps.

the class VisibleRegionDemoActivity method onMapReady.

@Override
public void onMapReady(GoogleMap map) {
    mMap = map;
    // Move to a place with indoor (SFO airport).
    mMap.setPadding(currentLeft, currentTop, currentRight, currentBottom);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SFO, 18));
    // Add a marker to the Opera House.
    mMap.addMarker(new MarkerOptions().position(SOH).title("Sydney Opera House"));
    // Add a camera idle listener.
    mMap.setOnCameraIdleListener(new OnCameraIdleListener() {

        @Override
        public void onCameraIdle() {
            mMessageView.setText("CameraChangeListener: " + mMap.getCameraPosition());
        }
    });
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) OnCameraIdleListener(com.google.android.libraries.maps.GoogleMap.OnCameraIdleListener)

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