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