1

El asunto es el siguiente, termine de hacer mi aplicación en la IDE de Android Studio, Al emular la app en el emulador o en un dispositivo físico va todo bien, el problema surge cuando genero la APK.

Ahora explico: Google maps se ve sin problemas al emular, no así al generar la APK por medio de Android Studio, esta se ve como si no reconociera la api-key osea no se refleja el mapa y no entiendo por que... Cabe recalcar que ya utilice "multiDexEnabled true", también genere la huella SHA-1 y el mapa sigue sin funcionar.

<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.

To get one, follow this link, follow the directions and press "Create" at the end:

https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=3A:64:19:43:62:19:28:63:12:A0:F2:39:79:F3:9A:05:1F:44:2F:51%3Bixtapa.com.mx.ixtapazihua

You can also add your credentials to an existing key, using this line:
3A:64:19:43:62:19:28:63:12:A0:F2:39:79:F3:9A:05:1F:44:2F:51;ixtapa.com.mx.ixtapazihua

Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key

Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
    AIzaSyDAgFUrcH2olG29IUClfIrSgqH4-wZ0AL8
</string>

Clase del Mapa

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
String lat = "";
String lon = "";
String Name= "";
String Address="";



int latI;
int lonI;
Double latD2, lonD2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Otain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);


    Intent i = getIntent();
    Bundle extra = i.getExtras();




    if (extra != null) {
        lat = (String) extra.get("Lat");
        lon = (String) extra.get("Lng");
        Name = (String) extra.get("Name");
        Address = (String) extra.get("Address");
    }
        //Toast.makeText(this, "Se recibieron los valores", Toast.LENGTH_SHORT).show();
        //Toast.makeText(this, lat + lon, Toast.LENGTH_SHORT).show();
    else {
        Toast.makeText(this, "No se reciben valores", Toast.LENGTH_LONG).show();
    }


    latD2 = Double.parseDouble(lat);
    lonD2 = Double.parseDouble(lon);






}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng Hotels = new LatLng(latD2, lonD2);
    mMap.addMarker(new MarkerOptions().position(Hotels).title(Name)
            .snippet(Address)
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(Hotels));

    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
            new LatLng(latD2, lonD2), 12));


    mMap.getUiSettings().setZoomControlsEnabled(true);



    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.



        return;
    }
    mMap.setMyLocationEnabled(true);

}

}

introducir la descripción de la imagen aquí

2
  • El título es demasiado general y parece que el código no se pasó correctamente ¿podrías modificar el título y corregir la indentación para que el formato de código se aplicque correctamente?
    – Rubén
    el 21 feb. 2017 a las 1:28
  • Una solución podría ser que no tiene los permisos habilitados en su dispositivo celular, diríjase a configuración, aplicaciones, busca su aplicación y habilita todos los permisos que esta le pida.
    – Byron
    el 1 may. 2018 a las 17:52

1 respuesta 1

1

Habilitar multiDexEnabled true no influye en este caso.

Si el mapa se muestra en el emulador o el dispositivo fisico significa que obtuviste el SHA-1 del Keystore de debug y obtuviste un API key el cual muestras.

Si deseas ver el mapa cuando creas el .APK este debe ser firmado con un Keystore de producción, si no lo tienes crea uno, ver Firmar tu App.

De este keystore con el cual firmaras tu aplicación debes obtener el SHA-1, y agregarlo para obtener el API KEY:

introducir la descripción de la imagen aquí

Esta API KEY que obtengas es la que configuraras en tu archivo.

En ocasiones es necesario intercambiar entre una y otra API KEY en tu archivo, ya sea cuando usas el emulador o subes directamente el .apk a tu dispositivo (API KEY obtenida del debug.keystore) o cuando generas un .apk que subiras a producción a la google play store.

Revisa esta respuesta: Maps Android Studio

6
  • ya realice todo lo correspondiente a la firma y al entrar a ver el LOGCAT no me arroja error con respecto al mapa y aun así no me muestra el mapa sigo sin comprender el por que del problema. el 21 feb. 2017 a las 18:43
  • puede que mi comentario te pueda sonar algo absurdo, revisa tu conexion wifi, datos o permisos,
    – Mark Dev
    el 21 feb. 2017 a las 19:03
  • Como comenta Mark, no es absurdo creo que puede ser entonces causa el no tener conectividad, comenta y nos dices.
    – Jorgesys
    el 21 feb. 2017 a las 19:13
  • claro no es absurdo cualquier aportación es muy importante a veces pequeñas cosas hacen mucha diferencia, pero ya revise los permisos que se necesitan, las librerías del Gradle y aun así el problema sigue persistente. el 21 feb. 2017 a las 19:50
  • Logre resolver el problema con el mapa, el error prevenía por que se tiene que colocar la llave de la Api en el archivo que se encuentra src/debug/ and src/release/ y generar una SH-1 de lanzamiento "keytool -list -v -keystore your_keystore_name -alias your_alias_name" el 21 feb. 2017 a las 20:35

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.