Use of api from google maps

0

In my app I use the Google Maps API. I use the api in 2 parts of the app, in one if it works correctly but in another does not show me the activity, my question is as follows: Once this is enabled in the app, it can be used anywhere and how many Sometimes are you wishing? Because when you launch the intent to another activity if you do it and when you throw it to the desired one, no. What happens when the desired activity is launched is that the screen is blank and returns to the previous activity, but it does not show me an error in the logcat. I try to launch the desired activity by pressing a button on a cardView.

Here I leave the code where I try to launch the activity, which is from the adapter for the cardviews:

@Override
public void onBindViewHolder(final EventoViewHolder viewHolder, final int pos) {

    nombreMonum = items.get(pos).getNombre();
    id = items.get(pos).getId();
    lat = items.get(pos).getLatitud();
    lon = items.get(pos).getLongitud();

    viewHolder.imagen.setImageResource(asignarImg(id));
    viewHolder.nombre.setText(items.get(pos).getNombre());
    viewHolder.descripcion.setText(items.get(pos).getDescripcion());
    viewHolder.galeria.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(act, Galeria.class );
            Log.i("Datos","id "+id);
            i.putExtra("id", id);
            act.startActivity(i);
        }
    });

    viewHolder.ir.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(act, MapsActivity.class );
            Log.i("Datos","nombreMonum "+ nombreMonum);
            Log.i("Datos","latitud "+lat);
            Log.i("Datos","longitud "+lon);
            i.putExtra("latitud", lat);
            i.putExtra("longitud", lon);
            i.putExtra("nombre", nombreMonum);
            act.startActivity(i);
        }
    });
}

and here where I pick it up:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    String nombre;
    Double lat, lon;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maps);

        nombre = getIntent().getExtras().getString("nombre");
        lat = getIntent().getExtras().getDouble("latitud");
        lon = getIntent().getExtras().getDouble("longitud");

        Log.i("seguimiento","nombre "+ nombre);
        Log.i("seguimiento","latitud "+lat);
        Log.i("seguimiento","longitud "+lon);
        //Localizan en el layout el id map
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        //le decimos al frasgment que lo obtenga de forma asincrona
        mapFragment.getMapAsync(this);

    }

    @Override
    public void onMapReady(GoogleMap map) {

        // Add a marker in Sydney, Australia, and move the camera.
        LatLng monumento = new LatLng(lat, lon);
        map.addMarker(new MarkerOptions().position(monumento).title(nombre).snippet("monumento"));
        map.moveCamera(CameraUpdateFactory.newLatLng(monumento));
        map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
    }

}

I also leave the .xml code:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    map:cameraZoom="16"
    tools:context=".Actividad.MapsActivity" />
    
asked by tripossi 17.02.2017 в 12:36
source

0 answers