Skip to content

Commit

Permalink
Fixes location issue in upload wizard (#5329)
Browse files Browse the repository at this point in the history
* Fixes location issue in upload wizard

* Fixes blue dot disappearance on first install
  • Loading branch information
srishti-R authored Oct 7, 2023
1 parent 8aee7a6 commit 048b78a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void onClickModifyLocation() {
/**
* Show the location in map app
*/
public void showInMap(){
public void showInMap() {
Utils.handleGeoCoordinates(this,
new fr.free.nrw.commons.location.LatLng(cameraPosition.target.getLatitude(),
cameraPosition.target.getLongitude(), 0.0f));
Expand Down Expand Up @@ -387,6 +387,8 @@ public void onFailure(@NonNull Exception exception) {
});


} else {
requestLocationPermissions();
}
}

Expand Down Expand Up @@ -458,13 +460,13 @@ void placeSelected() {
*/
private void addCenterOnGPSButton(){
fabCenterOnLocation = findViewById(R.id.center_on_gps);
fabCenterOnLocation.setOnClickListener(view -> getCenter());
fabCenterOnLocation.setOnClickListener(view -> requestLocationPermissions());
}

/**
* Center the map at user's current location
*/
private void getCenter() {
private void requestLocationPermissions() {
LocationPermissionsHelper.Dialog locationAccessDialog = new Dialog(
R.string.location_permission_title,
R.string.upload_map_location_access
Expand Down Expand Up @@ -539,6 +541,9 @@ public void onLocationPermissionDenied(String toastMessage) {

@Override
public void onLocationPermissionGranted() {
if (mapboxMap.getStyle() != null) {
enableLocationComponent(mapboxMap.getStyle());
}
fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation();
if (currLocation != null) {
final CameraPosition position;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.free.nrw.commons.location;

import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;

import android.Manifest.permission;
import android.app.Activity;
import android.content.Context;
Expand All @@ -9,7 +10,6 @@
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -59,9 +59,9 @@ private Location getLastKnownLocation() {
for (String provider : providers) {
Location l=null;
if (ActivityCompat.checkSelfPermission(getApplicationContext(), permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
== PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(getApplicationContext(), permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
== PackageManager.PERMISSION_GRANTED) {
l = locationManager.getLastKnownLocation(provider);
}
if (l == null) {
Expand Down

0 comments on commit 048b78a

Please sign in to comment.