2017-02-07 3 views
1

こんにちは私はGoogleマップで作業していますが、私が持っているマーカーにカスタムタイトルを作成すると、マーカーが選択されたときを知る必要があります。 becouse私はletmeはあなたに私が得たコードを貼り付け、その情報とフラグメントを開く必要があります:、私はカスタムタイトルから情報を送信する必要があり、私は新しいフラグメントと呼ばれる方法OnInfoWindowClickListenerでカスタムタイトルを取得するマーカー情報google maps

@Override 
    public void onMapReady(GoogleMap googleMap) { 
     map =googleMap; 
     map.getUiSettings().setZoomControlsEnabled(true); 


     for (Taxi taxi : taxis) { 
      u= taxi.getUbicacionActual(); 
      LatLng ubicacion= new LatLng(Double.parseDouble(u.getLatitud()), Double.parseDouble(u.getLongitud())); 


      map.moveCamera(CameraUpdateFactory.newLatLngZoom(ubicacion,15)); 

      MarkerOptions punto= new MarkerOptions().position(ubicacion); 
      map.addMarker(punto); 

      map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 
       @Override 
       public View getInfoWindow(Marker marker) { 

        return null; 
       } 

       @Override 
       public View getInfoContents(Marker marker) { 
        View v = getLayoutInflater().inflate(R.layout.info_title, null); 


        TextView info1 = (TextView) v.findViewById(R.id.info1); 
        TextView info2 = (TextView) v.findViewById(R.id.info2); 
        TextView info3 = (TextView) v.findViewById(R.id.info3); 

        info1.setText("Fecha: " + u.getFecha()); 
        info3.setText("Longitud: " + u.getLongitud().toString()); 

        info2.setText("Ubicacion: "+obtenerDireccion(u.getLatitud(),u.getLongitud())); 

        return v; 
       } 
      }); 


     } 
     map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { 
      @Override 
      public void onInfoWindowClick(Marker marker) { 

       Fragment fragmento; 
       fragmento = new HistorialFragment(); 
       getSupportFragmentManager().beginTransaction() 
         .replace(R.id.content_principal, fragmento) 
         .commit(); 


      } 
     }); 

を誰かください可能性これで私を助けてください?

答えて

1

はこれを試してみてください。

はあなたsetOnInfoWindowClickListenergetInfoContents(Marker marker)内部のメソッドを追加します。 :

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 
     @Override 
     public View getInfoWindow(Marker marker) { 

      return null; 
     } 

     @Override 
     public View getInfoContents(Marker marker) { 
      View v = getLayoutInflater().inflate(R.layout.info_title, null); 


      final TextView info1 = (TextView) v.findViewById(R.id.info1); 
      TextView info2 = (TextView) v.findViewById(R.id.info2); 
      TextView info3 = (TextView) v.findViewById(R.id.info3); 

      info1.setText("Fecha: " + u.getFecha()); 
      info3.setText("Longitud: " + u.getLongitud().toString()); 

      info2.setText("Ubicacion: "+obtenerDireccion(u.getLatitud(),u.getLongitud())); 

      map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { 
       public void onInfoWindowClick(Marker marker) 
       { 
        Fragment fragmento; 
        fragmento = new HistorialFragment(); 
        Bundle bundle = new Bundle(); 
        bundle.putString("title",info1.getText().toString()); 
        fragmento.setArguments(bundle); 
        getSupportFragmentManager().beginTransaction() 
          .replace(R.id.content_principal, fragmento) 
          .commit(); 
       } 
      }); 

      return v; 
     } 
    }); 
+0

ありがとう、多くの人今それは働いている:) –

0

あなたは

MarkerOptions punto= new MarkerOptions() 
    .position(ubicacion) 
    .title("Fecha: " + u.getFecha()); // set the marker title 
map.addMarker(punto); 

をやっMarkerのタイトルを設定した場合、あなたがやってonInfoWindowClick方法でそれを取得することができます。

map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { 
    @Override 
    public void onInfoWindowClick(Marker marker) { 
     String title = marker.getTitle(); // Retrieve the title 
    } 
}); 
+0

いいえ私は3つのテキストフィールドを持つカスタムウィンドウを作成し、そのうちの1つの情報が必要です。コードをチェックインすると、info1.setText( "Fecha:" + u.getFecha ()); –

+0

私は自分の答えを編集しました。マーカーのタイトルを設定し、それを 'onInfoWindowClick' – antonio

+0

でも使用できますが、メソッドで作成されたマーカー情報:public View getInfoContents(マーカーマーカー).titleを使用していません。カスタムウィンドウタイトルがあるのでビュー。 –

関連する問題