Je viens de créer une activité de carte avec des marqueurs et tout en cliquant sur le titre du marqueur aller chercher l'adresse de la position marquée à des fins éducatives, Tout fonctionne bien.Comment google carte adresse de recherche même appareil Android est hors ligne
Il récupère l'adresse même si l'appareil n'est pas connecté à Internet. Je n'ai pas donné d'autorisation internet dans le manifeste. ACCESS_FINE_LOCATION
est la seule autorisation donnée à l'application.
Ma question est: Comment l'application est-elle capable d'obtenir l'adresse même si l'appareil est en mode hors ligne? Quelle est l'idée ou la technologie derrière tout ça?
Nb:Je n'ai jamais utilisé la méthode getLastKnownLocation
dans mon code. Le Wifi et le GPS sont désactivés et aucune carte SIM n'est insérée.
Voici mon code:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
TextView mapPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mapPosition = (TextView) findViewById(R.id.textplace);
// 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;
// double lat = Double.valueOf(8.524139);
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151); LatLng ind = new LatLng(8.524139, 76.936638);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.addMarker(new MarkerOptions().position(ind).title("Marker in Trivandrum"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(ind));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
return false;
}
});
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());
try {
addresses = geocoder.getFromLocation(marker.getPosition().latitude, marker.getPosition().longitude, 1);
// Here 1 represent max location result to returned, by documents it recommended 1 to 5
String address = addresses.get(0).getAddressLine(0);
// If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
String countrycode = addresses.get(0).getCountryCode();
mapPosition.setText(""+ address);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
donc vous dites que l'application 'Maps' de Google peut fonctionner sans accès en ligne et peut trouver l'adresse, montrer des cartes, trouver un itinéraire entre 2 points, etc. – pskink
Je n'ai pas vérifié les itinéraires, mais la carte fonctionne bien sans internet. –
nous parlons de l'adresse, non? comme '10 Downing St, Westminster, Londres SW1A 2AA, Royaume-Uni', et pas' 51.503396 ° N 0.127640 ° W' – pskink