Problem google maps api not shown map

1

The issue is as follows, finish making my application in the IDE of Android Studio, When emulating the app in the emulator or a physical device is all good, the problem arises when I generate the APK.

Now explain: Google maps is seen without problems to emulate, not so when generating the APK through Android Studio, it looks like it does not recognize the api-key bone is not reflected in the map and I do not understand why. .. It should be noted that you already use "multiDexEnabled true", also generate the SHA-1 fingerprint and the map still does not work.

<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>

Class of the Map

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);

}

}

    
asked by Julio César 21.02.2017 в 02:12
source

1 answer

1

Enabling multiDexEnabled true does not affect this case.

If the map is shown in the emulator or the physical device it means that you got the SHA-1 from the debug Keystore and you got an API key which you sample.

If you want to see the map when you create the .APK this must be signed with a production Keystore, if you do not have one, see Sign your App .

From this keystore with which you will sign your application you must obtain the SHA-1, and add it to obtain the KEY API:

This KEY API that you get is the one that you will configure in your file.

Sometimes it is necessary to exchange between one and another API KEY in your file, either when you use the emulator or upload the .apk directly to your device (API KEY obtained from the debug.keystore) or when you generate a .apk that you will upload to production at the google play store.

Review this answer: Maps Android Studio

    
answered by 21.02.2017 в 04:22