How to display text when tap on marker in google m

2019-08-11 06:00发布

I want to display like this.

https://lh6.ggpht.com/DOvS0NiHGyGC9Vn7JvkwznRBZ7I65j3zwpNAqLkP5y083ju7JQbwWi4NAXQLp5Wsavmn=h900 When google map marker gets tap, text will display below. It can be drag up and down. I don't get how it has been done.

public class MapsActivity extends FragmentActivity
{
Googlemap gm;

gm = ((SupportMapFragment) (getSupportFragmentManager()
            .findFragmentById(R.id.map))).getMap();
gm.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gm.setOnInfoWindowClickListener(this);
@Override
public void onInfoWindowClick(Marker marker) {
    String a=marker.getTitle();
   // how to display this title in same screen below with dragging up and down when map marker been tap

}
    }

Please help me to solve this issue.Thanks in advance.

3条回答
狗以群分
2楼-- · 2019-08-11 06:16

You have to create hidden layout for it. Create one layout as per your need and do it GONE by default. But when you click like below and inflate that layout in you onClick method:

    gm.setOnInfoWindowClickListener(this);
    @Override
    public void onInfoWindowClick(Marker marker) {
        String a=marker.getTitle();
        LayoutInflater inflater;
        inflater = LayoutInflater.from(context);
        View view;
        view = adapterInflater.inflate(R.layout.adapter_add_event, null);
       // how to display this title in same screen below with dragging up and down when map marker been tap

}

And visible this layout, do findViewById and make it visible.

查看更多
祖国的老花朵
3楼-- · 2019-08-11 06:21

or.. If your marker is draggable, use the following snippet

        map.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {

        @Override
        public void onMarkerDragEnd(Marker marker) {
            marker.setSnippet("Your Text");
            map.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));

        }

    });
查看更多
男人必须洒脱
4楼-- · 2019-08-11 06:34

implement this method instead of infoWindowClick

gm.setOnMarkerClickListener(new OnMarkerClickListener() {

    @Override
    public boolean onMarkerClick(Marker arg0) {
    // TODO Auto-generated method stub
            String title = "Any Thing You want";
                marker.setTitle(title);
                textView.setText("title");
        return true;
    }
});
查看更多
登录 后发表回答