Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why marker's info window doesn't show?

I am stuck couldn't figour out why info window doesn't show up when I click on map's marker. I read on developer android site that only should I add marker and give them title, snippet and so on. But the result is nothing.

public class ClubMapActivity extends DefaultActivity implements GoogleMap.OnMarkerClickListener {
    private GoogleMap mMap;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.clubmap);
        Bundle bundle = getIntent().getExtras();
        double lat = bundle.getDouble("latitude");
        double lng = bundle.getDouble("longitude");


        mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        mMap.addMarker(new MarkerOptions()
                .position(new LatLng(lat, lng))
                .title(bundle.getString("clubNmae")).snippet("AAA"));

        animateCameraTo(lat, lng);
        CameraUpdate zoom=CameraUpdateFactory.zoomTo(20);

        mMap.animateCamera(zoom);


    }

    public void animateCameraTo(final double lat, final double lng)
    {
        CameraUpdate center=
                CameraUpdateFactory.newLatLng(new LatLng(lat, lng));
        CameraUpdate zoom=CameraUpdateFactory.zoomTo(18);

        mMap.moveCamera(center);
        mMap.animateCamera(zoom);
    }


    @Override
    public boolean onMarkerClick(Marker marker) {
        if(marker.isInfoWindowShown()) {
            marker.hideInfoWindow();
        } else {
            marker.showInfoWindow();
        }
        return true;
    }
}
like image 765
pmb Avatar asked Aug 23 '13 18:08

pmb


3 Answers

By default, an info window is displayed when a user taps on a marker if the marker has a title set.

Make sure your .title(bundle.getString("clubNmae") is returning not null value otherwise you cannot see the info window when clicking on the marker.

like image 97
fish40 Avatar answered Sep 28 '22 21:09

fish40


It doesn't look like you are calling setOnMarkerClickListener.

https://developers.google.com/maps/documentation/android/marker

like image 29
Sofi Software LLC Avatar answered Sep 28 '22 19:09

Sofi Software LLC


Adding to @fish40 answer above: title must be not only NotNull but also NotEmpty, i.e. even if you pass "" as the marker title, the info window will not show up.

like image 33
kouretinho Avatar answered Sep 28 '22 20:09

kouretinho