Android Google Maps V2: How to Add Marker with Multiline Snippet

Android Google Maps v2: How to add marker with multiline snippet?

It looks like you will need to create your own "info window" contents to make that work:

  1. Create an implementation of InfoWindowAdapter that overrides getInfoContents() to return what you want to go into the InfoWindow frame

  2. Call setInfoWindowAdapter() on your GoogleMap, passing an instance of your InfoWindowAdapter

This sample project demonstrates the technique. Replacing my snippets with "foo\nbar" correctly processes the newline. However, more likely, you will just come up with a layout that avoids the need for the newline, with separate TextView widgets for each line in your desired visual results.

Marker multiple snippet Google Maps API 2

I think you should try to use Custom info windows for Google Maps Android API v2

To do this, you must create a concrete implementation of the InfoWindowAdapter interface and then call GoogleMap.setInfoWindowAdapter() with your implementation.

The interface contains two methods for you to implement: getInfoWindow(Marker) and getInfoContents(Marker). The API will first call getInfoWindow(Marker) and if null is returned, it will then call getInfoContents(Marker). If this also returns null, then the default info window will be used.

For more details, please refer to here, and here

Google Maps snippet show more text

You may want to look into a custom InfoWindowAdapter depending on how much you're being tasked with here. They have some decent documentation here https://developers.google.com/maps/documentation/android-api/infowindows. I've had to do quite a bit with these, so if the documentation isn't enough, let me know.

As far as what code would help us, you're going to want to find where you're adding the markers, these markers are adding the snippet data from the locations you're pulling in. Those markers also have Info Windows that if you need to customize how much and what they show, you can do by using methods found at that link. Hope this helps.

Map Marker with Muliline Info Window

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.

Add a carriage return into a Google Maps Snippet

You will have to create your own info window View using GoogleMap.setInfoWindowAdapter. The default info window implementation seems to remove newlines.

How to set a custom marker title for google maps

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"?>
<LinearLayout xmlns: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">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">

<ImageView
android: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" />

<LinearLayout
android:id="@+id/text_lay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="3dp">

<TextView
android: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" />

<TextView
android: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:

public class InfoWindowAdapter implements GoogleMap.InfoWindowAdapter, CommonValues, BundleTags {

private View view;

private FragmentActivity myContext;

public InfoWindowAdapter(FragmentActivity aContext) {
this.myContext = aContext;

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

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

@Override
public View getInfoContents(Marker marker) {

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

@Override
public View getInfoWindow(final Marker marker) {

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

final String snippet = marker.getSnippet();
final TextView snippetUi = ((TextView) view
.findViewById(R.id.snippet));

if (snippet != null) {

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

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

return view;
}
}

How to do multiple lines in GoogleMaps marker snippet in Swift?

Hahaha, "\n" LOL???

"\n" should get parsed as a standard new line.

So result would be this?

marker.snippet = time + "\n" + speed


Related Topics



Leave a reply



Submit