集InfoWindowAdapter显示信息仅供点击第一个标记 [英] set InfoWindowAdapter show information only for first marker clicked

查看:400
本文介绍了集InfoWindowAdapter显示信息仅供点击第一个标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我已经设置 infowindowadapter 我的谷歌地图,但问题是,当我点击第一个标志,它正确显示的信息,但是当我打第二个标志是表示从第一个信息,因此 infowindowadapter 不会刷新。

So, I have set infowindowadapter for my Google map, but the problem is that when I click on the first marker, it shows the information correctly, but when I hit the second marker it shows information from the first one, so infowindowadapter doesn't refresh.

谁能告诉我,为什么它,以及如何解决它?

Can someone tell me why that it and how to fix it?

我在下面这个帖子设置 infowindowadapter

I was following this post to set infowindowadapter:

<一个href=\"http://stackoverflow.com/questions/15090148/custom-info-window-adapter-with-custom-data-in-map-v2/15091202#15091202\">custom信息窗口适配器在地图V2 自定义数据

编辑:

    new getMarkers().execute();

    mMap.setOnMarkerClickListener(new OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            marker.showInfoWindow();
            return false;
        }
    });
    mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker marker) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {

            View view = getLayoutInflater().inflate(R.layout.post_details_on_map,null);

            date = (TextView)view.findViewById(R.id.txtMarkerDate);
            comment = (TextView)view.findViewById(R.id.txtMarkerComment);
            image = (ImageView)view.findViewById(R.id.ivMarkerPicture);

            MyMarkerInfo mmi = markerMap.get(marker.getId());
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("id",mmi.getId()));

            MarkerDetails mDetails = new JSONAdapter().getMarkerDetails(params);
            date.setText(mDetails.getDate());
            comment.setText(mDetails.getComment());

            new getPicture().execute(mDetails.getImageUrl());
            return view;
        }
    });

}

推荐答案

下面是我的code完全相同的操作:

Here is my code for exactly the same operation:

    // Setting a custom info window adapter for the google map
        map.setInfoWindowAdapter(new InfoWindowAdapter() {

            // Use default InfoWindow frame
            @Override
            public View getInfoWindow(Marker args) {
                return null;
            }

            // Defines the contents of the InfoWindow
            @Override
            public View getInfoContents(Marker args) {

                // Getting view from the layout file info_window_layout
                View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);

                // Getting the position from the marker
                clickMarkerLatLng = args.getPosition();

                TextView title = (TextView) v.findViewById(R.id.tvTitle);
                title.setText(args.getTitle());

                map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {          
                    public void onInfoWindowClick(Marker marker) 
                    {
                        if (SGTasksListAppObj.getInstance().currentUserLocation!=null)
                        {   
                            if (String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) &&
                                    String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLongitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
                            {
                                Toast.makeText(getApplicationContext(), "This your current location, navigation is not needed.",  Toast.LENGTH_SHORT).show();
                            }
                            else
                            {
                                FlurryAgent.onEvent("Start navigation window was clicked from daily map");
                                tasksRepository = SGTasksListAppObj.getInstance().tasksRepository.getTasksRepository();
                                for (Task tmptask : tasksRepository)
                                {
                                    String tempTaskLat = String.valueOf(tmptask.getLatitude());
                                    String tempTaskLng = String.valueOf(tmptask.getLongtitude());

                                    Log.d(TAG, String.valueOf(tmptask.getLatitude())+","+String.valueOf(clickMarkerLatLng.latitude).substring(0, 8));

                                    if (tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
                                    {  
                                        task = tmptask;
                                        break;
                                    }
                                }
                                /*
                                findDirections(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude(),
                                               SGTasksListAppObj.getInstance().currentUserLocation.getLongitude(),
                                               clickMarkerLatLng.latitude, clickMarkerLatLng.longitude, GMapV2Direction.MODE_DRIVING );
                                */
                                Intent intent = new Intent(getApplicationContext() ,RoadDirectionsActivity.class);
                                intent.putExtra(TasksListActivity.KEY_ID, task.getId());
                                startActivity(intent);

                            }
                        }
                        else
                        {
                            Toast.makeText(getApplicationContext(), "Your current location could not be found,\nNavigation is not possible.",  Toast.LENGTH_SHORT).show();
                        }
                    }
                });

                // Returning the view containing InfoWindow contents
                return v;

            }
        });

我的猜测是,你越来越其他标记信息的错误的方式。试试我的方法和你之间进行比较,并尝试登录的过程中看到要传递正确的Id和获得正确的信息。

My guess would be that your are getting other markers information the wrong way. try to compare between my method and yours, and try to log the process to see that you are passing the right Id and getting the right info.

这篇关于集InfoWindowAdapter显示信息仅供点击第一个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆