-1

The text in the follow code is not displayed completely within the info window (shown below):

mMap.addMarker(new MarkerOptions().position(the_local_user2).title("My Title").snippet("My Snippet"+"\n"+"1st Line Text"+"\n"+"2nd Line Text"+"\n"+"3rd Line Text")
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

enter image description here

I would like it to look similar to this:

enter image description here

I found Marker-Plugins SDK, but I do not know if it is good or not.

How can I get the info window to display multiline text?

Bryan
  • 14,756
  • 10
  • 70
  • 125
Json
  • 59
  • 3
  • 13

1 Answers1

2

You can create a custom info window with multiline text.

To do this all you have to do is implement GoogleMap.InfoWindowAdapter in your Activity and inflate a custom View for the info window. Then call GoogleMap#setInfoWindowAdapter.

public class MapActivity extends AppCompatActivity imeplements OnMapReadyCallback, GoogleMap.InfoWindowAdapter {

    private GoogleMap mGoogleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstaceState);
        setContentView(r.layout.activity_map);

        SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        fragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        googleMap.setInfoWindowAdapter(this);
        mGoogleMap = googleMap;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        return null; // Use default info window background
    }

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

        TextView titleTextView = (TextView) view.findViewById(R.id.title);
        TextView snippetTextView = (TextView) view.findViewById(R.id.snippet);

        titleTextView.setText(marker.getTitle());
        snippetTextView.setText(marker.getSnippet());

        return view;
    }

}

Also, the Cordova GoogleMaps Plugin is for applications that use either the Cordova or PhoneGap development frameworks; not for native Android development. The Google Maps Android API is meant for native development; which it seems you are already making use of. Do not confuse the two.

Bryan
  • 14,756
  • 10
  • 70
  • 125