How to display text when tap on marker in google maps android

给你一囗甜甜゛ 提交于 2019-12-11 11:22:25

问题


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.


回答1:


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;
    }
});



回答2:


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:


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()));

        }

    });


来源:https://stackoverflow.com/questions/19291938/how-to-display-text-when-tap-on-marker-in-google-maps-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!