Skip to content

Instantly share code, notes, and snippets.

@maiconhellmann
Created December 2, 2017 14:07
Show Gist options
  • Save maiconhellmann/435fc44bd82a889a6485df17a64c684d to your computer and use it in GitHub Desktop.
Save maiconhellmann/435fc44bd82a889a6485df17a64c684d to your computer and use it in GitHub Desktop.
Custom map Marker in Java
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_your_image" />
</merge>
private MarkerOptions createMarkerIcon(LatLng position) {
FrameLayout frameLayout = new FrameLayout(getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
frameLayout.setLayoutParams(params);
View markerView = getActivity().getLayoutInflater().inflate(R.layout.custom_map_marker, frameLayout);
BitmapDescriptor bitmapMerged = BitmapDescriptorFactory.fromBitmap(BitmapUtils.createDrawableFromView(getContext(), markerView));
return new MarkerOptions()
.icon(bitmapMerged)
.position(position)
.infoWindowAnchor(0.5f, 3.2f)
.snippet("id=1");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment