2013-03-28 57 views
2

因此,我已爲我的Google地圖設置infowindowadapter,但問題是,當我點擊第一個標記時,它顯示正確的信息,但是當我點擊第二個標記時顯示來自第一個的信息,因此infowindowadapter不刷新。設置InfoWindowAdapter只顯示第一個標記點​​擊信息

有人可以告訴我爲什麼它,以及如何解決它?

我下面這個職位設置infowindowadapter

custom info window adapter with custom data in map 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; 
     } 
    }); 

}

+0

我已編輯我的帖子 – toskebre

+0

剛纔我嘗試setOnMarkerClickListner並在其中調用marker.showinfowindow(),希望它會再次調用getInfoContent,但沒有任何改變。 – toskebre

回答

7

這裏是我的一模一樣的操作碼:

// 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並獲取正確的信息。

+0

你說得對。我的同事在他的PHP腳本中犯了錯誤,他只在我的腳本中返回了我定義的ID,但未收到我的請求ID xD Ty for your help,只要我獲得足夠的聲譽,我就可以投票回覆 Cheers – toskebre

+1

很棒發現你的問題,有一個很好的編碼:) –

+1

謝謝,你也:) – toskebre

相關問題