[JAVA] Customize infoWindow for google maps for Android

0. Execution example

スクリーンショット 2019-03-13 11.47.17.png

1.setInfoWindowAdapter() In GoogleMap.setInfoWindowAdapter (), set the object that implements InfoWindowAdapter interface (implement getInfoWindow () or getContents ()).

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
    private GoogleMap mMap;
//~ Abbreviation ~
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
            @Override
            public View getInfoWindow(Marker marker) {
                return null;    //Describe the process in either
            }

            @Override
            public View getInfoContents(Marker marker) {
                return null;    //Describe the process in either
            }

2. Describe the layout of InfoWindow

Create a new layout resource file in res / layout / and describe the layout of infoWindow. Add description in res / values / strings.xml as needed.

info_window_ayout.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/iw_1"/>
    <TextView
        android:id="@+id/tv_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/iw_2"/>
    <TextView
        android:id="@+id/tv_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/iw_3"/>
    <Button
        android:id="@+id/bt_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/bt_1"/>

</LinearLayout>

strings.xml


<resources>
<!--~ Abbreviation ~-->
    <string name="iw_1">Information on the first line</string>
    <string name="iw_2">Information on the second line</string>
    <string name="iw_3">Information on the third line</string>
    <string name="bt_1">You can also put a button</string>
</resources>

3. Implementation of getInfoContents ()

            @Override
            public View getInfoContents(Marker marker) {
                View view = getLayoutInflater().inflate(R.layout.info_window_layout,null);
                return view;
            }

reference

[Customize InfoWindow](https://seesaawiki.jp/w/moonlight_aska/d/%A5%A4%A5%F3%A5%D5%A5%A9%A5%A6%A5%A3%A5%F3 % A5% C9% A5% A6% A4% F2% A5% AB% A5% B9% A5% BF% A5% DE% A5% A4% A5% BA% A4% B9% A4% EB) [Info Windows | Maps SDK for Android | Google Developers] (https://developers.google.com/maps/documentation/android-sdk/infowindows#custom_info_windows)

Recommended Posts

Customize infoWindow for google maps for Android
python for android Toolchain
Implemented in-app purchase for Android Google Play Billing Library 2.0
About the camera change event of Google Maps Android API
The most polite way to use the Google Maps SDK for iOS