Google Maps does not load

Asked

Viewed 2,316 times

0

I created an application to test google maps, but when I run by mobile the map does not load...a logo of google appears in the bottom left corner but the rest of the screen is blank... I added the permissions on Androidmanifest.xml, and the phone is connected to the internet...I don’t know how to proceed

Androidmanifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="etec.googlemaps">

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Mapsactivity

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

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


    /**
     * 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 sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

    }
}

Tela:

  • The debug shows nothing?

  • I solved my problem with Andre Souza’s answer at the link below https://groups.google.com/forum/#! topic/androidbrasil-dev/gR27Z9bMEWA

3 answers

1


The Key Api you generated will only work if you use the same Store to generate the apk. In Android Studio, Build menu -> Generate Signed APK, and choose the Keystore used to generate the key Api.

  • What do you mean, man? I’m new

  • On your Androidmanifest.xml you have a tag referring to an API_KEY, did you generate it or just copied it from a tutorial? If it didn’t generate, take a look at Ivo Bruno Silva’s answer, because you’ll need it to access the maps.

  • Yes, I managed the KEY API

  • Ok. To generate the KEY API, at some point you used a file. Keystore, go to Build -> Generate Signed APK and use the same file. Keystore to sign the apk.

  • In my case I used the debug.Keystore, located on .android... so I must sign the apk with it?

  • Man, it worked out... THANKS!!!!!

  • I have a similar problem. You can help me with: http://answall.com/questions/120345/google-maps-n%C3%A3o-load-on-physical device

Show 2 more comments

0

friend your application will only work if you have the key of maps: go to your code file "res/values/google_maps_api.xml"

find that line of code:

<name="google_maps_key" translatable="false" templateMergeStrategy="preserve">ADD_API_KEY_HERE   <--
</string>

and replace the ADD_API_KEY_HERE with the one provided by the pros of the google site

https://developers.google.com/maps/signup

  • Dude, I did it.. t with the KEY API

0

You need to create a maps project( here) for it to give you a key. This key should be added in your google_maps_api.xml file where it will be: ADD_API_KEY_HERE. In order for you to get a key to replace in the file I mentioned above you will need to generate a sha-1 that is shown in the link I added.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.