Сделайте так, чтобы маркер Google Maps Android обрабатывал несколько строк - PullRequest
0 голосов
/ 02 июля 2019

как сделать так, чтобы маркер Google Maps Android обрабатывал несколько строк? сейчас он показывает только одну строку

см. Название этого маркера для справки

1 Ответ

0 голосов
/ 02 июля 2019

1) Простой способ - использовать "\ n" в заголовке маркера:

driversMarker = mMap.addMarker(new MarkerOptions()
                                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.bike_top_left))
                                            .title("Click To Call.\n again nextline")
                                            .snippet("Driver ID: " + key)
                                            .position(location));

2) Другой способ - использовать настраиваемый адаптер информационного окна:

Layout Xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="center_horizontal"
            android:gravity="center"
            android:background="@android:color/white"

         >



                <TextView
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:id="@+id/txtPickupInfo"
                    android:text="Pickup Here"
                    android:textStyle="bold"
                    />
                <TextView
                    android:layout_width="200dp"
                    android:layout_height="wrap_content"
                    android:id="@+id/txtPickupSnippet"
                    android:text="Optional"
                    android:textStyle="bold"
                    />

            </LinearLayout>

Java: CustomInfoWindow:

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.Marker;

public class CustomInfoWindow   implements GoogleMap.InfoWindowAdapter {


    View myView;

    public CustomInfoWindow(Context context) {
        myView=LayoutInflater.from(context).inflate(R.layout.custom_rider_info_window,null);
    }

    @Override
    public View getInfoWindow(Marker marker) {
        TextView textPickupTitle = ((TextView)myView.findViewById(R.id.txtPickupInfo));
        TextView textPickupSnippet = ((TextView)myView.findViewById(R.id.txtPickupSnippet));

        textPickupTitle.setText(marker.getTitle());
        textPickupSnippet.setText(marker.getSnippet());

        return myView;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }
}

Использование:

public class MapActivity extends AppCompatActivity
        implements GoogleMap.OnInfoWindowClickListener {






 @Override
    public void onInfoWindowClick(Marker marker) {

 // do something when click the info window.

}



  @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

mMap.setInfoWindowAdapter(new CustomInfoWindow(this));
mMap.setOnInfoWindowClickListener(this);

} 

}

При настройке маркера:

 if(driversMarker!=null)
 driversMarker.showInfoWindow();
...