0

Estou aprendendo Android sozinho, pela internet e estou trabalhando dessa vez com API do Google Maps. Já fiz várias coisas com ela no Android Studio, exibindo, utilizando marker, geolocalização, entre outras funções. Porém quando ontem fiz o APK e rodei na maquina virtual NOX ou em celulares, o mapa da API não está renderizando. Ele roda o aplicativo, faz as funções do aplicativo, só não renderiza o mapa.

inserir a descrição da imagem aqui

Por exemplo, nesse aplicativo abaixo, quando você clica no mapa (mesmo não renderizado) ele exibe na tela os dados do local(pais, bairro,cidade,etc).

ps: Ele não da nenhum erro, em nenhum momento. Apenas o mapa não renderiza no celular. Android Studio funciona normalmente.

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private Marker marker;
private ArrayList<LatLng> list;
private ArrayAdapter<String> adpDados;
private ArrayList<Double> recebeLatLng;

ArrayList []vet = new ArrayList[4];

double auxLat, auxLng;
int cont;
 SQLiteDatabase conn;
 RepositórioTabela repositórioTabela;
SQLiteDatabase db;


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

}


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    list = new ArrayList<LatLng>();

    LatLng sydney = new LatLng(-34, 151);

    LatLng Rio = new LatLng(-23.2301558,-42.9121089);
    mMap.addMarker(new MarkerOptions().position(Rio));
    LatLng bdDados = new LatLng(auxLat,auxLng);
    customAddMarker(bdDados);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Rio,0));

    LatLng PERTH = new LatLng(-31.90,115.86);



    try {
        DataBase dataBase = new DataBase(this);

        conn = dataBase.getWritableDatabase();
        repositórioTabela = new RepositórioTabela(conn);

       //   repositórioTabela.buscaTabelaLatLng(this);
       vet = repositórioTabela.buscaTabelaLatLng(this);

        ArrayList auxList = vet[1];
        ArrayList auxList2 = vet[2];

        for (int i= 0;i<auxList.size();i++){

            double auxLatN = (double)auxList.get(i);
            double auxLngN = (double)auxList2.get(i);
            customAddMarker(new LatLng(auxLatN,auxLngN));
        }






    } catch (SQLException EX) {
        AlertDialog.Builder dlg = new AlertDialog.Builder(this);
        dlg.setMessage("Erro" + EX.getMessage());
        dlg.setNeutralButton("Ok", null);
        dlg.show();

    }
        mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {
            Log.i("Script", "setOnMapClickListener()");
      /*      if(marker != null){
                marker.remove();
            } */



            customAddMarker(new LatLng(latLng.latitude, latLng.longitude));
            list.add(latLng);

            View view = null;

              getLocation(view);


            //   drawRoute();

        }
    });


}


public void customAddMarker(LatLng latLng ){

    MarkerOptions options = new MarkerOptions();
    options.position(latLng);

 //   marker = mMap.addMarker(options);


    // Lembrar de fazer o DELETE MARKER NESSA CLASS
}




public void getLocation(View view){
    // https://developer.android.com/reference/android/location/Address.html

    Geocoder gc = new Geocoder(MapsActivity.this);

    List<Address> addressList;
    try {
        addressList = gc.getFromLocation(list.get(list.size() - 1).latitude, list.get(list.size() - 1).longitude, 1);
        //  addressList = gc.getFromLocationName("Rua Vergueiro, Sãoo Paulo, São Paulo, Brasil", 1);

        String address = "Rua: " + addressList.get(0).getThoroughfare() + "\n"; // Rua
        address += "Postal Code: " + addressList.get(0).getPostalCode() + "\n"; // Postal Code
        address += "Numero: " + addressList.get(0).getFeatureName() + "\n";   // Numero
        address += "Cidade: " + addressList.get(0).getLocality() + "\n";
        address += "Estado: " + addressList.get(0).getAdminArea() + "\n";
        address += "Pais: " + addressList.get(0).getCountryName() + "\n";
        address += "Latitude: " + addressList.get(0).getLatitude() + "\n";
        address += "Longitude: " + addressList.get(0).getLongitude() + "\n";
        address += "Bairro: " + addressList.get(0).getSubLocality() + "\n"; // Bairro

        //  ListaTarefas listaTarefas = new ListaTarefas();
        //  listaTarefas.markDado = "kkkk";

        String lat = "" + addressList.get(0).getLatitude();
        String lng = "" + addressList.get(0).getLongitude();
        // DATA BASE 1

        repositórioTabela = new RepositórioTabela(conn);
        for (long i = 0; i <= 500; i++) {
          //   repositórioTabela.excluir(i);
        }

        repositórioTabela.testeInserirContatos(address,lat,lng);




        Toast.makeText(MapsActivity.this, "Local: "+address, Toast.LENGTH_LONG).show();
        //  Toast.makeText(MapsActivity.this, "LatLng: "+ll, Toast.LENGTH_LONG).show();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}

public void irParaTarefas(View v){
    Intent intentAux1 = new Intent(getApplicationContext(),ListaTarefas.class);
    // aux.setClass(this,Calculadora.class);
    startActivity(intentAux1);
}

E abaixo meu manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.moorg.alertmaps">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">


    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />

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

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

    <activity android:name=".PontoCerto"></activity>
    <activity android:name=".ListaTarefas"></activity>

</application>

5
  • Pode ser problema de permissões. Qual versão do Android do celular?
    – ramaral
    19/05/2017 às 14:52
  • Eu testei em dois celulares, android 6.0 e 5.1. E em ambos dão o mesmo erro. Testei no android 4.4, 7.0 e 5 ou 6 no android studio e ambos funcionaram 19/05/2017 às 14:58
  • Dá erro ou apenas o mapa não aparece?
    – ramaral
    19/05/2017 às 15:02
  • Não da erro nenhum, em nenhum momento. Apenas não exibe. Deixa eu tentar mandar print 19/05/2017 às 15:10
  • O print ficou meio grande, mas fica assim. Se eu clicar no lugar do mapa, ele vai exibir o lugar onde eu cliquei. (cidade, estado, etc). E se eu for em tarefas os dados vão aparecer lá. (o layout de tarefas funciona perfeitamente) 19/05/2017 às 15:13

1 Resposta 1

1

Eu estava com esse problema e consegui resolver. Só precisei abrir AndroidMainifest e mudar a parte onde é solicitado o API Key do maps. Ao invés de indicar a chave usando string, digitei a chave direto. Ficou assim: Antes:

<meta-data-->
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

Depois:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="digitei a API KEY aqui" />
1
  • Como não se trata de um código executável como javascript, não é necessário usar snippet.
    – user28595
    7/01/2018 às 12:24

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 .