java – Android谷歌地图添加到标记自己的标签

前端之家收集整理的这篇文章主要介绍了java – Android谷歌地图添加到标记自己的标签前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这样的代码
protected void onPostExecute(final ArrayList<HashMap<String,String>> adapter) {

                for (final HashMap<String,String> a : adapter) {
                    LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)),Double.valueOf(a.get(TAG_longitude)));
                    Log.e("pppppos",String.valueOf(pos.latitude));
                    Marker m = map.addMarker(new MarkerOptions().position(pos)
                            .title(a.get(TAG_NAME))
                            .snippet("Kiel is cool"));

                    map.setOnInfoWindowClickListener(
                              new OnInfoWindowClickListener(){
                                    public void onInfoWindowClick(Marker marker){
                                      Intent nextScreen = new Intent(SearchExchangerActivity.this,BankExchangersListActivity.class);
                                        nextScreen.putExtra("exchanger_id",id);    
                                        startActivityForResult(nextScreen,0);
                                    }
                                  });
                }

但是我需要为用户字段设置不可见,例如每个标记的Tag_id,然后在向其他活动发送额外的信息时使用此id,如下所示:

protected void onPostExecute(final ArrayList<HashMap<String,String>> adapter) {

            for (final HashMap<String,String> a : adapter) {
                LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)),Double.valueOf(a.get(TAG_longitude)));
                Marker m = map.addMarker(new MarkerOptions().position(pos)
                        .title(a.get(TAG_NAME))
                        .snippet("Kiel is cool")
                                                    .Tag_id(TAG_ID));

                map.setOnInfoWindowClickListener(
                          new OnInfoWindowClickListener(){
                                public void onInfoWindowClick(Marker marker){
                                  Intent nextScreen = new Intent(SearchExchangerActivity.this,BankExchangersListActivity.class);
                                    nextScreen.putExtra("exchanger_id",marker.get(TAG_ID));    
                                    startActivityForResult(nextScreen,0);
                                }
                              });
            }

真的吗?我怎么能在我的听众中获得我点击的标记

也可以通过标题字段来完成…但是我在编写marker.getTitle()…时收到错误

UPD

for (final HashMap<String,Double.valueOf(a.get(TAG_longitude)));
                Log.e("pppppos",String.valueOf(pos.latitude));
                HashMap<Marker,String> m = new HashMap<Marker,String>();
                        m.put( map.addMarker(new MarkerOptions().position(pos)
                        .title(a.get(TAG_NAME))
                        .snippet("Kiel is cool")),"1");                    

            }

            map.setOnInfoWindowClickListener(
              new OnInfoWindowClickListener(){
                    public void onInfoWindowClick(HashMap<Marker,String> marker){
                      Intent nextScreen = new Intent(SearchExchangerActivity.this,BankExchangersListActivity.class);
                        nextScreen.putExtra("exchanger_id","1");   
                        startActivityForResult(nextScreen,0);
                    }
                  });

解决方法

>您可以使用Map< Marker,String>并保留您的数据
>使用 Android Maps Extensions,它将getData和setData函数添加到Marker类.

顺便说一句.您不应该将InfoWindowAdapter设置为循环.这个不成立.只有最后的生存.

原文链接:https://www.f2er.com/android/125343.html

猜你在找的Android相关文章