2013-03-16 116 views
1

我正在創建一個方法,當點擊標記的信息框/代碼片段時運行。至今,我找不到任何關於此的信息,只有標記。任何幫助或鏈接到哪裏我可以找到更多的信息?Android標記點擊功能

+1

務必先檢查API文檔:https://developers.google.com/maps/documentation/android/marker#info_window_click_events – moujib 2013-03-16 23:17:12

回答

7

創建一個運行的方法,當你點擊你需要setOnInfoWindowClickListener信息窗口:

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; 
            } 
           } 

           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(); 
         } 
        } 
       }); 
+0

你已經基本上回答了一個問題,我是要去有後來問及我問的那個,非常感謝! – 2013-03-16 23:15:33

+0

我會的時候它允許我。 – 2013-03-16 23:20:41

+0

你忘了在'getInfoContents'中返回視圖 – ElliotM 2014-11-05 22:49:31

0

剛剛成立OnInfoWindowClickListener爲您的地圖。

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { 
     @Override 
     public void onInfoWindowClick(Marker marker) { 
     //YOUR CODE 
     } 
    });