how to Make Google Maps Android marker title handle multiple lines? right now, it only shows one line
Asked
Active
Viewed 789 times
-1
-
It seems your image link is invalid , getting `502 bad gateway` . Please check it once. – xaif Jul 02 '19 at 14:06
-
1@xaif i dont get this eror – Jul 02 '19 at 14:12
-
1the image is useless anyway – Jul 02 '19 at 14:12
-
Hope it helps , 1) . https://stackoverflow.com/questions/15090148/custom-info-window-adapter-with-custom-data-in-map-v2/15091202#15091202 2)https://stackoverflow.com/questions/43374214/google-maps-can-you-make-string-inside-snippet-bold – xaif Jul 02 '19 at 14:17
-
1Possible duplicate of [custom info window adapter with custom data in map v2](https://stackoverflow.com/questions/15090148/custom-info-window-adapter-with-custom-data-in-map-v2) – Will Da Silva Jul 02 '19 at 15:04
1 Answers
0
1) A simple way is use "\n" in Marker title :
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) Another Way is use custom info window adapter :
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;
}
}
Uses :
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);
}
}
When you Setup your Marker :
if(driversMarker!=null)
driversMarker.showInfoWindow();

Noor Hossain
- 1,620
- 1
- 18
- 25