Skip to content Skip to sidebar Skip to footer

How To Set A Custom Marker Title For Google Maps

How do I set a styled custom marker title/snippet that includes information and a button? I already have a custom marker icon image set. Now I need a custom pop up window that will

Solution 1:

Use a Custom layout design and add it to your Google Map. Here refer this below sample code and customize your design.

Window Design:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/custom_info_bubble"android:gravity="center"android:orientation="vertical"android:paddingBottom="40dp"android:paddingLeft="10dp"android:paddingRight="10dp"android:paddingTop="10dp"><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_vertical"><ImageViewandroid:id="@+id/badge"android:layout_width="30dp"android:layout_height="30dp"android:layout_centerVertical="true"android:layout_toRightOf="@+id/text_lay"android:background="@drawable/icn_right_arrow" /><LinearLayoutandroid:id="@+id/text_lay"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center_vertical"android:orientation="vertical"android:padding="3dp"><TextViewandroid:id="@+id/title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:fontFamily="sans-serif"android:padding="3dp"android:singleLine="true"android:text="title"android:textColor="#ff000000"android:textSize="@dimen/text_size_small" /><TextViewandroid:id="@+id/snippet"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:fontFamily="sans-serif"android:padding="3dp"android:text="45 bays  available"android:textColor="@color/green"android:textSize="14dp" /></LinearLayout></RelativeLayout>

Java class for Window Adapter:

publicclassInfoWindowAdapterimplementsGoogleMap.InfoWindowAdapter, CommonValues, BundleTags {

private View view;

private FragmentActivity myContext;

publicInfoWindowAdapter(FragmentActivity aContext) {
    this.myContext = aContext;

    LayoutInflaterinflater= (LayoutInflater) myContext.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    view = inflater.inflate(R.layout.layout_inflate_parking_info_window,
            null);
}

@Overridepublic View getInfoContents(Marker marker) {

    if (marker != null
            && marker.isInfoWindowShown()) {
        marker.hideInfoWindow();
        marker.showInfoWindow();
    }
    returnnull;
}

@Overridepublic View getInfoWindow(final Marker marker) {

    finalStringtitle= marker.getTitle();
    finalTextViewtitleUi= ((TextView) view.findViewById(R.id.title));
    if (title != null) {
        titleUi.setText(title);
    } else {
        titleUi.setText("");
        titleUi.setVisibility(View.GONE);
    }

    finalStringsnippet= marker.getSnippet();
    finalTextViewsnippetUi= ((TextView) view
            .findViewById(R.id.snippet));

    if (snippet != null) {

        String[] SnippetArray = snippet.split(SEPARATOR);


        snippetUi.setText(SnippetArray[0]);
    } else {
        snippetUi.setText("");
    }

    return view;
  }
}

Solution 2:

This is a link to an easy answer only using Title and Snipped: Have a look at https://stackoverflow.com/a/31629308/7877442

Post a Comment for "How To Set A Custom Marker Title For Google Maps"