3
I am making an application that uses the Google Maps API for Android. The problem is that it only displays the map if it is connected to the Internet.
How can I download the map of a certain region and make it available in the application, to work while the device is disconnected?
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(map);
mapFragment.getMapAsync(this);
//Versão do Android a partir do 6.0 precisa desse 'resquest' para permissões de GPS e Localização
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
checkLocationPermission();
// Tratamento de exceção, caso o serviço de localização nao esteja ativo chama a função
// que habilita o GPs e/ou localização
try {
checkGps();
} catch (Exception e) {
createNoGpsDialog();
}
}
//Versão do Android a partir do 6.0 precisa desse 'resquest' para permissões de GPS e Localização
//Mostra uma caixa de Dialogo para o usuario se ele permite ou não a ativação do GPS ou Localização
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case 1: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
}else{}
}
}
}
public boolean checkLocationPermission(){
String permission = "android.permission.ACCESS_FINE_LOCATION";
int res = this.checkCallingOrSelfPermission(permission);
return (res == PackageManager.PERMISSION_GRANTED);
}
//---------------------------------------------------------------
@Override
public void onMapReady(GoogleMap map) {
// Tipo do Mapa
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, 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;
}
//Minha Posição Atual
map.setMyLocationEnabled(true);
// Posicao inicial onde o mapa abre
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(-27.3246787, -53.4387937), (float) 14.5));
}
You could better detail your problem and add the codes you have so far?
– Lucas Kauer
Okay, I added my map of my application, how it works, I’m using the maps API for android, only that this api needs internet to show me the map, no internet has no usefulness the map, I know it has how to download the map to celualar and use in gps, but what I want to know is if there’s a way for me to put the map next to the app, so that the user doesn’t need the internet to view the map. Installing my app it ha install the map along.
– user59669
Take a look at this link here: http://stackoverflow.com/questions/14784841/tileprovider-using-local-tiles
– Gabriel Polidoro