Skip to content

Commit 048b78a

Browse files
authored
Fixes location issue in upload wizard (commons-app#5329)
* Fixes location issue in upload wizard * Fixes blue dot disappearance on first install
1 parent 8aee7a6 commit 048b78a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

app/src/main/java/fr/free/nrw/commons/LocationPicker/LocationPickerActivity.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private void onClickModifyLocation() {
314314
/**
315315
* Show the location in map app
316316
*/
317-
public void showInMap(){
317+
public void showInMap() {
318318
Utils.handleGeoCoordinates(this,
319319
new fr.free.nrw.commons.location.LatLng(cameraPosition.target.getLatitude(),
320320
cameraPosition.target.getLongitude(), 0.0f));
@@ -387,6 +387,8 @@ public void onFailure(@NonNull Exception exception) {
387387
});
388388

389389

390+
} else {
391+
requestLocationPermissions();
390392
}
391393
}
392394

@@ -458,13 +460,13 @@ void placeSelected() {
458460
*/
459461
private void addCenterOnGPSButton(){
460462
fabCenterOnLocation = findViewById(R.id.center_on_gps);
461-
fabCenterOnLocation.setOnClickListener(view -> getCenter());
463+
fabCenterOnLocation.setOnClickListener(view -> requestLocationPermissions());
462464
}
463465

464466
/**
465467
* Center the map at user's current location
466468
*/
467-
private void getCenter() {
469+
private void requestLocationPermissions() {
468470
LocationPermissionsHelper.Dialog locationAccessDialog = new Dialog(
469471
R.string.location_permission_title,
470472
R.string.upload_map_location_access
@@ -539,6 +541,9 @@ public void onLocationPermissionDenied(String toastMessage) {
539541

540542
@Override
541543
public void onLocationPermissionGranted() {
544+
if (mapboxMap.getStyle() != null) {
545+
enableLocationComponent(mapboxMap.getStyle());
546+
}
542547
fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation();
543548
if (currLocation != null) {
544549
final CameraPosition position;

app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.free.nrw.commons.location;
22

33
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
4+
45
import android.Manifest.permission;
56
import android.app.Activity;
67
import android.content.Context;
@@ -9,7 +10,6 @@
910
import android.location.LocationListener;
1011
import android.location.LocationManager;
1112
import android.os.Bundle;
12-
import android.util.Log;
1313
import androidx.core.app.ActivityCompat;
1414
import java.util.HashSet;
1515
import java.util.List;
@@ -59,9 +59,9 @@ private Location getLastKnownLocation() {
5959
for (String provider : providers) {
6060
Location l=null;
6161
if (ActivityCompat.checkSelfPermission(getApplicationContext(), permission.ACCESS_FINE_LOCATION)
62-
!= PackageManager.PERMISSION_GRANTED
62+
== PackageManager.PERMISSION_GRANTED
6363
&& ActivityCompat.checkSelfPermission(getApplicationContext(), permission.ACCESS_COARSE_LOCATION)
64-
!= PackageManager.PERMISSION_GRANTED) {
64+
== PackageManager.PERMISSION_GRANTED) {
6565
l = locationManager.getLastKnownLocation(provider);
6666
}
6767
if (l == null) {

0 commit comments

Comments
 (0)