title: I'm having problems with the geolocation in my android app
body: <p>I'm trying to create an app using android studio, i'm having a problem with geolocation specifically i'm trying to use a button to get the device location, but it doesn't work. This is the code that i'm using:</p>
  <pre><code>public void position(View view) {
          if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
              fusedLocationProviderClient.getLastLocation().addOnCompleteListener(new OnCompleteListener&lt;Location&gt;() {
  
                  public void onComplete(@NonNull Task&lt;Location&gt; task) {
                      Location location = task.getResult();
                      if (location != null) {
  
                          try {
                              Geocoder geocoder = new Geocoder(MainActivity.this, Locale.getDefault());
                              List&lt;Address&gt; addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
                              latitudine = addresses.get(0).getLatitude();
                              longitudine = addresses.get(0).getLongitude();
                              LatLng localizzazione = (new LatLng(latitudine, longitudine));
                              mMap.addMarker(new MarkerOptions().position(new LatLng(latitudine, longitudine)).icon(BitmapDescriptorFactory.fromResource(R.drawable.posizionegif)));
                              mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(localizzazione, 12));
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
  
                      }
  
                  }
              });
  
          } else {
              ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 44);
  
          }
  
      }
  </code></pre>
  <p>Hope you can help me. Thanks :)</p>