I'm learning Android alone, over the internet and I'm working this time with the Google Maps API. I've done several things with it in Android Studio, displaying, using marker, geolocation, among other functions. But when I did the APK yesterday and rode the NOX virtual machine or mobile phones, the API map is not rendering. It runs the application, does the application's functions, just does not render the map.
Forexample,inthisapplicationbelow,whenyouclickonthemap(evenifitisnotrendered)itdisplaysthelocationdata(country,neighborhood,city,etc.)onthescreen.
ps:Hegivesnoerroratallinnotime.Onlythemapdoesnotrenderonthephone.AndroidStudioworksnormally.
publicclassMapsActivityextendsFragmentActivityimplementsOnMapReadyCallback{privateGoogleMapmMap;privateMarkermarker;privateArrayList<LatLng>list;privateArrayAdapter<String>adpDados;privateArrayList<Double>recebeLatLng;ArrayList[]vet=newArrayList[4];doubleauxLat,auxLng;intcont;SQLiteDatabaseconn;RepositórioTabelarepositórioTabela;SQLiteDatabasedb;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_maps);//ObtaintheSupportMapFragmentandgetnotifiedwhenthemapisreadytobeused.SupportMapFragmentmapFragment=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);mapFragment.getMapAsync(this);}@OverridepublicvoidonMapReady(GoogleMapgoogleMap){mMap=googleMap;mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);list=newArrayList<LatLng>();LatLngsydney=newLatLng(-34,151);LatLngRio=newLatLng(-23.2301558,-42.9121089);mMap.addMarker(newMarkerOptions().position(Rio));LatLngbdDados=newLatLng(auxLat,auxLng);customAddMarker(bdDados);mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Rio,0));LatLngPERTH=newLatLng(-31.90,115.86);try{DataBasedataBase=newDataBase(this);conn=dataBase.getWritableDatabase();repositórioTabela=newRepositórioTabela(conn);//repositórioTabela.buscaTabelaLatLng(this);vet=repositórioTabela.buscaTabelaLatLng(this);ArrayListauxList=vet[1];ArrayListauxList2=vet[2];for(inti=0;i<auxList.size();i++){doubleauxLatN=(double)auxList.get(i);doubleauxLngN=(double)auxList2.get(i);customAddMarker(newLatLng(auxLatN,auxLngN));}}catch(SQLExceptionEX){AlertDialog.Builderdlg=newAlertDialog.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);
}
And below my 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>