Foros del Web » Programando para Internet » Android »

Dos SupportMapFragment en una misma app

Estas en el tema de Dos SupportMapFragment en una misma app en el foro de Android en Foros del Web. Hola a todos!! Estaba haciendo pruebas en donde tengo en un tab un mapa con unos puntos. Al tratar de incluir otro tab con otro ...
  #1 (permalink)  
Antiguo 04/02/2015, 08:57
 
Fecha de Ingreso: julio-2008
Ubicación: Buenos Aires, Mar del plata
Mensajes: 250
Antigüedad: 15 años, 9 meses
Puntos: 2
Dos SupportMapFragment en una misma app

Hola a todos!!
Estaba haciendo pruebas en donde tengo en un tab un mapa con unos puntos. Al tratar de incluir otro tab con otro mapa y con otros puntos, el mapa ya no se visuaiza bien.
Investigando encontré que no se puede. Es así?
No puedo utilizar el mismo mapa para limpiarlo y mostrar otros puntos?

Gracias!!!
  #2 (permalink)  
Antiguo 04/02/2015, 16:00
Avatar de ipraetoriux  
Fecha de Ingreso: abril-2010
Ubicación: ipraetoriux.com
Mensajes: 1.125
Antigüedad: 14 años
Puntos: 155
Respuesta: Dos SupportMapFragment en una misma app

Haber, pare empezar podes tener 1 o mas MapFragment en una misma aplicacion, ya que a cada mapa lo trabajas en fragmetns diferentes. Hay que ver como estas haciendo. Pone los .java y .xml para ver.
  #3 (permalink)  
Antiguo 04/02/2015, 16:37
 
Fecha de Ingreso: julio-2008
Ubicación: Buenos Aires, Mar del plata
Mensajes: 250
Antigüedad: 15 años, 9 meses
Puntos: 2
Respuesta: Dos SupportMapFragment en una misma app

Hola!
Acá adjunto el código. En principio esto anda. El problema se da cuando quiero agregar otro tab con otros puntos dándole un punto X determinado en lugar de tomarlo del location (actual)..

Código Java:
Ver original
  1. public class Tab1 extends FragmentActivity {
  2.     private LocationManager locManager;
  3.     public Double latitud;
  4.     public Double longitud;
  5.     private LatLng markerLatLng;
  6.     private LatLng markerLatLngP;
  7.        
  8.      public GeoPoint[] point;
  9.      public OverlayItem[] overlayitem;
  10.      public List<Grafiti> grafiti_Lst = Activity_Principal.getGeoPointLst();
  11.  
  12.       private GoogleMap googleMap;
  13.       private Marker marker;
  14.       private Hashtable<String, String> markers;
  15.       private ImageLoader imageLoader;
  16.       private DisplayImageOptions options;
  17.      
  18.   @Override
  19.   protected void onCreate(Bundle savedInstanceState) {
  20.       super.onCreate(savedInstanceState);
  21.       setContentView(R.layout.tab1);
  22.      
  23.       googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
  24.       initImageLoader();
  25.  
  26.       markers = new Hashtable<String, String>();
  27.       imageLoader = ImageLoader.getInstance();
  28.      
  29.       options = new DisplayImageOptions.Builder()
  30.                       .showStubImage(R.drawable.img_carga2)                             //          Display Stub Image
  31.                       .showImageForEmptyUri(R.drawable.img_error)                       //          If Empty image found
  32.                       .cacheInMemory()
  33.                       .cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();
  34.  
  35.         //SACO LAS COORDENADAS ACTUALES
  36.         locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  37.         Location loc = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  38.                     if(loc != null)
  39.                          {
  40.                               latitud = Double.valueOf(loc.getLatitude());
  41.                               longitud = Double.valueOf(loc.getLongitude());
  42.                          }
  43.  
  44.        markerLatLng = new LatLng(latitud, longitud);
  45.  
  46.       if ( googleMap != null ) {
  47.  
  48.               generateMap();
  49.               googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
  50.               googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(markerLatLng, 14));
  51.               googleMap.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);
  52.       }
  53.   }
  54.  
  55.   private class CustomInfoWindowAdapter implements InfoWindowAdapter {
  56.  
  57.               private View view;
  58.  
  59.               public CustomInfoWindowAdapter() {
  60.                       view = getLayoutInflater().inflate(R.layout.balloon, null);
  61.               }
  62.  
  63.               @Override
  64.               public View getInfoContents(Marker marker) {
  65.  
  66.                       if (Tab1.this.marker != null && Tab1.this.marker.isInfoWindowShown()) {
  67.                           Tab1.this.marker.hideInfoWindow();
  68.                           Tab1.this.marker.showInfoWindow();
  69.                       }
  70.                       return null;
  71.               }
  72.  
  73.               @Override
  74.               public View getInfoWindow(final Marker marker) {
  75.                   Tab1.this.marker = marker;
  76.                  
  77.                       String url = null;
  78.                       if (marker.getId() != null && markers != null && markers.size() > 0) {
  79.                               if ( markers.get(marker.getId()) != null &&
  80.                                               markers.get(marker.getId()) != null) {
  81.                                       url = markers.get(marker.getId());
  82.                               }
  83.                       }
  84.                       final ImageView image = ((ImageView) view.findViewById(R.id.imgP));
  85.  
  86.                       if (url != null && !url.equalsIgnoreCase("null")
  87.                                       && !url.equalsIgnoreCase("")) {
  88.                               imageLoader.displayImage(url, image, options,
  89.                                               new SimpleImageLoadingListener() {
  90.                                                       @Override
  91.                                                       public void onLoadingComplete(String imageUri,
  92.                                                                       View view, Bitmap loadedImage) {
  93.                                                               super.onLoadingComplete(imageUri, view, loadedImage);
  94.                                                               getInfoContents(marker);
  95.                                                       }
  96.                                               });
  97.                       } else {
  98.                               image.setImageResource(R.drawable.map_error);
  99.                               imagen_error = 1;
  100.                       }
  101.            
  102.                       return view;
  103.               }
  104.       }
  105.  
  106.   private void initImageLoader() {
  107.               int memoryCacheSize;
  108.               if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
  109.                       int memClass = ((ActivityManager)
  110.                                       getSystemService(Context.ACTIVITY_SERVICE))
  111.                                       .getMemoryClass();
  112.                       memoryCacheSize = (memClass / 8) * 1024 * 1024;
  113.               } else {
  114.                       memoryCacheSize = 2 * 1024 * 1024;
  115.               }
  116.               final ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
  117.                               this).threadPoolSize(5)
  118.                               .threadPriority(Thread.NORM_PRIORITY - 2)
  119.                               .memoryCacheSize(memoryCacheSize)
  120.                               .memoryCache(new FIFOLimitedMemoryCache(memoryCacheSize-1000000))
  121.                               .denyCacheImageMultipleSizesInMemory()
  122.                               .discCacheFileNameGenerator(new Md5FileNameGenerator())
  123.                               .tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging()
  124.                               .build();
  125.               ImageLoader.getInstance().init(config);
  126.       }
  127.  
  128. private void generateMap() {
  129.  
  130.     LatLng markerLatLngP1 = new LatLng(latitud, longitud);
  131.    
  132.         //Posición actual
  133.                 googleMap.addMarker(new MarkerOptions()
  134.                     .position(markerLatLngP1)
  135.                     .anchor(0.5f, 1)
  136.                     .icon(BitmapDescriptorFactory.fromResource(R.drawable.places_current)));
  137.  
  138.        //Recorro el vector de latitud y longitud y voy agregando los puntos al mapa.
  139.        for (int i = 0; i < g_Lst.size(); i++)
  140.         {
  141.         markerLatLngP = new LatLng((g_Lst.get(i).getLatitud()),(g_Lst.get(i).getLongitud()));
  142.  
  143.         final Marker kiel = googleMap.addMarker(new MarkerOptions()
  144.             .position(markerLatLngP)
  145.             .title(g_Lst.get(i).getNombre())
  146.             .snippet(g_Lst.get(i).getImagen())
  147.             .anchor(0.5f, 1)
  148.             .icon(BitmapDescriptorFactory.fromResource(R.drawable.places)));
  149.          markers.put(kiel.getId(), g_Lst.get(i).getImagen());
  150.  
  151.          markerLatLngP = null;
  152.          googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
  153.  
  154.            @Override
  155.            public void onInfoWindowClick(Marker marker) {
  156.                
  157.                if (imagen_error == 1){
  158.                    imagen_error = 0;
  159.                    return;
  160.                }
  161.                
  162.                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
  163.                 sharingIntent.setType("text/plain");
  164.  
  165.                 String post = "texto";
  166.                 sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  167.                 startActivity(Intent.createChooser(sharingIntent, "Texto"));
  168.                 }
  169.             });
  170.         }
  171.   }
  172. }

Código XML:
Ver original
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    xmlns:tools="http://schemas.android.com/tools"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    tools:context=".MainActivity" >
  6.     <fragment
  7.        android:id="@+id/map"
  8.        android:layout_width="match_parent"
  9.        android:layout_height="match_parent"
  10.        class="com.google.android.gms.maps.SupportMapFragment" />
  11. </RelativeLayout>

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:23.