Created
December 2, 2017 14:07
-
-
Save maiconhellmann/435fc44bd82a889a6485df17a64c684d to your computer and use it in GitHub Desktop.
Custom map Marker in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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