2013-04-08 58 views
0

有没有办法启动另一个活动点击谷歌地图V2弹出窗口的意图?Android地图v2点击弹出

这是我的代码:

@Override 
public View getInfoContents(Marker marker) 
{ 
    View popup=inflater.inflate(R.layout.popup, null); 

    final TextView tvtitulo=(TextView)popup.findViewById(R.id.tvTitulo); 
    TextView tvDatos=(TextView)popup.findViewById(R.id.tvDatos); 
    TextView tvCat=(TextView)popup.findViewById(R.id.tvCategoria); 

    tvtitulo.setText(marker.getTitle()); 

    StringTokenizer tokens = new StringTokenizer(marker.getSnippet(), "?"); 
    final String first = tokens.nextToken();// this will contain "Fruit" 
    String second = tokens.nextToken();// this will contain " they taste good" 

    tvDatos.setText(first); 
    tvCat.setText(second); 

    ImageView imagen = (ImageView)popup.findViewById(R.id.menuImgView); 

    if(marker.getTitle().substring(0,3).equalsIgnoreCase("Bar")) 
     imagen.setBackgroundResource(R.drawable.bar); 

    else if(marker.getTitle().substring(0,3).equalsIgnoreCase("Res")) 
     imagen.setBackgroundResource(R.drawable.rest); 
    else 
     imagen.setVisibility(4); 

    return(popup); 
} 

我想这样补充一点,就是方法内:

popup.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent intent = new Intent(getApplicationContext(), InfoLocal.class); 
      startActivity(intent); 
      finish(); 
     } 
    }); 

THX你的答案和我的英语很抱歉。

回答

0

是有,下面就来看看我是怎么做的,你必须在代码中的注释,了解正在发生的事情:

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

      } 
     }); 
+0

THX,它的工作完美 – user2257057 2013-04-08 10:34:54

+0

欢迎你@ user2257057,有一个很好的编码:) – 2013-04-08 10:49:59

+0

我放置在弹出的对话框按钮,并写在地图的onclicklistener .setInfoWindowAdapter()方法为按钮。但它不是我rking ...做什么? @EmilAdz – Venkat 2013-04-29 03:51:10

0

是的,但如果你只是想默认视图点击而不能提供你自己的,你只需要这样:

googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { 
      public void onInfoWindowClick(Marker marker) 
      { 
      //do sth with your click 

      } 
     });