0

In my app, I have to show the information about the marker at position. This is my work code.

mPerth = mMap.addMarker(new MarkerOptions()
        .position(PERTH)
        .title("Perth")
        .snippet("Population: Perth")
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
mPerth.showInfoWindow();

This looks like this image: enter image description here

I want looks like this iamge: enter image description here If you have any method, please vote me.

CleanCoder
  • 332
  • 3
  • 14

2 Answers2

0

Try this.

marker.setInfoWindowAnchor(1f,1f)

https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker#public-void-setinfowindowanchor-float-anchoru,-float-anchorv

Edit:

For a custom infoWindow you have to make a concrete implementation of GoogleMap.InfoWindowAdapter and inflate your custom_info_window_layout.xml file in the getInfoWindow(Marker marker) method.

public class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

Activity context;
CustomInfoWindow(Activity  context){
    this.context =context;
}

@Override
public View getInfoWindow(Marker marker) {
    View view = context.getLayoutInflater().inflate(R.layout.custom_info_window_layout, null);

    TextView title =(TextView) view.findViewById(R.id.tv_title);
    TextView snippet =(TextView) view.findViewById(R.id.tv_snippet);

    title.setText(marker.getTitle());
    snippet.setText(marker.getSnippet());

    return view;
}

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

}

And finally set this CustomInfoWindowAdapter on the map.

map.setInfoWindowAdapter(new CustomInfoWindowAdapter(MainActivity.this))
0
static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker marker = mMap.addMarker(new MarkerOptions()
                    .position(PERTH)
                    .anchor(0.5,0.5)
                    .rotation(90.0)
                    .infoWindowAnchor(0.5,0)); // add this line

enter image description here

Specifies the point in the marker image at which to anchor the info window when it is displayed. The default is the top middle of the image.

Community
  • 1
  • 1
Rahul
  • 3,293
  • 2
  • 31
  • 43