2

それで、infowindowadapterGoogleマップに設定しましたが、最初のマーカーをクリックすると情報が正しく表示されますが、2番目のマーカーをクリックすると最初のマーカーの情報が表示されるため、infowindowadapter更新されません。

誰かがその理由とそれを修正する方法を教えてもらえますか?

この投稿に従って設定しましたinfowindowadapter

マップ 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;
        }
    });

}

4

1 に答える 1

8

まったく同じ操作のコードは次のとおりです。

    // 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 を渡し、正しい情報を取得していることを確認してください。

于 2013-03-28T14:54:53.770 に答える