2013-03-16 74 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 
     } 
    });