在Android中的谷歌地图位置设置名称和标题

时间:2012-12-04 04:48:19

标签: android google-maps geolocation google-maps-markers

  

可能重复:
  iphone like annotation on android map

我正在实施一个使用谷歌地图的应用程序。到目前为止我成功地在谷歌地图上标记了位置。但我真正需要的是在谷歌地图位置上设置标题。就像下面的图片一样。

有人可以帮帮我吗? 感谢。

enter image description here

3 个答案:

答案 0 :(得分:2)

它基本上叫做Mapview Ballons。以下是在github上开发的示例项目供您参考。它对我的项目有很大的帮助。

Mapview Ballons

希望它对你有所帮助。

答案 1 :(得分:0)

您可以使用onTap方法在ItemizedOverlay中使用Alertbox / Dialog ..

您可以标记任意数量的地方,也可以在Google地图位置的顶部设置标题。

例如

    public void onCreate(Bundle b)
    {
        super.onCreate(b);
        try{  

            setContentView(R.layout.main);
            System.out.println(""+lati+place+longi+position.get(0)+position.size());
            mapView=(MapView)findViewById(R.id.map_view);
            mapView.setBuiltInZoomControls(true); 

            mc = mapView.getController();
            mc.setZoom(12);

            drae=this.getResources().getDrawable(R.drawable.ic_launcher);
            test tt=new test(drae,this);        
            tt.addit(latitude,longitude, place_name);
            tt.addit(latitude1,longitude1, place_name1);
            mapView.getOverlays().add(tt);
            System.out.println(ii);

            break;
        }


        default:
            System.out.println(position.size());
        }
    }
}

        }catch (Exception e) {
          System.out.println(e.getMessage());
        } 
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    class test extends ItemizedOverlay
    {
        List<OverlayItem>overLayItem=new ArrayList<OverlayItem>();
        Context con;
        public test(Drawable drae,Context con) {

            super(boundCenterBottom(drae));
            testt(con);
        }

        void testt(Context con)
        {
            this.con=con;
        }
        @Override
        protected OverlayItem createItem(int i) {
            return overLayItem.get(i);
        }

        @Override
        public int size() {
            return overLayItem.size();
        }

        protected boolean onTap(int index) {
            // TODO Auto-generated method stub
            OverlayItem ir=overLayItem.get(index);
            AlertDialog.Builder dia=new AlertDialog.Builder(con);
            dia.setTitle(ir.getTitle());
            dia.setMessage(ir.getSnippet());
            dia.setPositiveButton("close",new  DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();
                }
            });
            dia.show();
            return true;
        }


        public void additem(OverlayItem item)
        {
            overLayItem.add(item);
            populate();
        }
        public void addit(int l,int g,String s)
        {
            GeoPoint po=new GeoPoint(l, g);
            OverlayItem it=new OverlayItem(po,s,null);
            additem(it);
        }
    }
}

答案 2 :(得分:0)

看一下刚刚发布的新Google Maps Android API v2。它使用信息窗口(带标题和片段)添加标记变得更加容易 - 请参阅documentation以获取示例。