简体   繁体   English

点击地图上的标记时如何显示信息窗口?

[英]How to show an info window on tapping a marker on map?

when i searched for it i found these links as solutions: 当我搜索它时,我发现这些链接可以作为解决方案:

http://android-codes-examples.blogspot.in/2011/04/google-map-example-in-android-with-info.html http://android-codes-examples.blogspot.in/2011/04/google-map-example-in-android-with-info.html

and

https://github.com/jgilfelt/android-mapviewballoons https://github.com/jgilfelt/android-mapviewballoons

but i found both are complicated. 但我发现两者都很复杂。

I am wondering if there is any simple way to do this. 我想知道是否有任何简单的方法可以做到这一点。 Like inflating a layout and showing it as a pop up just on the marker clicked. 就像放大版式,并在单击的标记上将其显示为弹出窗口一样。

Right now i am using just a Toast to show info when user taps on the marker. 现在,当用户点击标记时,我仅使用Toast来显示信息。 But the main problem is I want this toast(or other layout) to appear just above the marker which is clicked, not at the default toast position. 但是主要的问题是我希望此烤面包(或其他布局)出现在被单击的标记上方,而不是在默认的烤面包位置。

Thank You 谢谢

Try this, modify according to your requirement: 试试看,根据您的要求进行修改:

@SuppressWarnings({ "deprecation" })
    @Override
    protected boolean onTap(int index)
    {
        CustomView customView=new CustomView(MyMap.this);
        absMap.removeAllViews();
        absMap.addView(customView);
        customView.setBackgroundResource(R.drawable.maplocation1);
        customView.setVisibility(View.INVISIBLE);

        customView.removeAllViews();

          absMap.invalidate();
          customView.bringToFront();
          customView.setVisibility(View.VISIBLE);
          TextView tv2=new TextView(MyMap.this);
        //  tv2.setText(overlayItemList.get(index).getTitle());
          tv2.setWidth(170);
          tv2.setSingleLine(true);
          tv2.setEllipsize(TruncateAt.END);
          tv2.setSingleLine(true);
          tv2.setSingleLine();

          tv2.setTextColor(Color.WHITE);
          tv2.setTextSize(14);
          tv2.setTypeface(Typeface.DEFAULT_BOLD);

          TextView tv1=new TextView(MyMap.this);
          tv1.setSingleLine();
          tv1.setWidth(170);
          tv1.setSingleLine(true);
          tv1.setEllipsize(TruncateAt.END);
          tv1.setSingleLine(true);
          tv2.setText(overlayItemList.get(index).getSnippet());


          tv1.setTextColor(Color.WHITE);
          tv1.setTextSize(12);
          tv1.setTypeface(Typeface.DEFAULT_BOLD);
          customView.setTag(overlayItemList.get(index).getTitle());
          customView.addView(tv2, new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,10,5));
          customView.addView(tv1, new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,10,25));
          customView.setLayoutParams(new MapView.LayoutParams( 250, 100, overlayItemList.get(index).getPoint(),-125,-137, MapView.LayoutParams.MODE_MAP|MapView.LayoutParams.TOP_LEFT));
          customView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) 
            {
            }
        });


    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM