0

Criei uma aplicação pra testar o google maps, porém quando eu executo pelo celular o mapa não carrega...a logo da google aparece no canto inferior esquerdo mas o resto da tela fica em branco...Eu adicionei as permissões no AndroidManifest.xml, e o celular está conectado a internet...não sei como proceder

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:

2

3 Respostas 3

1

A Api Key que você gerou só vai funcionar se usar a mesma keystore pra gerar o apk. No Android Studio, menu Build -> Generate Signed APK, e escolha a keystore usada para gerar a Api key.

7
  • Como assim cara? Sou novato
    – Filip3
    20/03/2016 às 22:03
  • No teu AndroidManifest.xml tem uma tag referente a uma API_KEY, você gerou ela ou só copiou de algum tutorial? Se não gerou dá uma olhada na resposta do Ivo Bruno Silva, pq você vai precisar dela pra ter acesso ao maps. 20/03/2016 às 22:09
  • Sim, eu gerei a API KEY
    – Filip3
    20/03/2016 às 23:44
  • Ok. Pra gerar a API KEY, em algum momento você usou um arquivo .keystore, vá em Build -> Generate Signed APK e use o mesmo arquivo .keystore pra assinar o apk. 21/03/2016 às 0:09
  • No meu caso eu usei a debug.keystore, localizada na .android...então eu devo assinar o apk com ela?
    – Filip3
    24/03/2016 às 15:08
0

amigo a sua aplicação só vai funcionar se tiver a key do maps: vá nesse arquivo do seu código "res/values/google_maps_api.xml"

ache essa linha de código:

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

e troque o ADD_API_KEY_HERE pela fornecida do prósito site do google developer

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

1
  • Cara, eu fiz isso..ta com a API KEY
    – Filip3
    20/03/2016 às 20:35
0

Você precisa criar uma projeto do maps( aqui) para que este te entregue uma chave. Essa chave deve ser adicionada no seu arquivo google_maps_api.xml onde vai estar: ADD_API_KEY_HERE. Para que você consiga uma chave para substituir no arquivo que citei acima você precisará gerar um sha-1 que é mostrado no link que adicionei.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .