Skip to content

Commit 452f799

Browse files
ashishkumar468misaochan
authored andcommitted
Fixes commons-app#3260, handle null latlng when adding current location marker (commons-app#3261)
1 parent 7b9e792 commit 452f799

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyMapFragment.java

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package fr.free.nrw.commons.nearby.fragments;
22

3+
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
4+
35
import android.content.Context;
46
import android.graphics.Bitmap;
57
import android.os.Bundle;
68
import android.util.AttributeSet;
79
import android.view.LayoutInflater;
810
import android.view.View;
911
import android.view.ViewGroup;
10-
1112
import androidx.annotation.NonNull;
1213
import androidx.annotation.Nullable;
1314
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
14-
1515
import com.mapbox.mapboxsdk.annotations.Icon;
1616
import com.mapbox.mapboxsdk.annotations.IconFactory;
1717
import com.mapbox.mapboxsdk.annotations.Marker;
@@ -26,13 +26,6 @@
2626
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
2727
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
2828
import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
29-
30-
import java.util.ArrayList;
31-
import java.util.HashMap;
32-
import java.util.List;
33-
34-
import javax.inject.Inject;
35-
3629
import fr.free.nrw.commons.R;
3730
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
3831
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
@@ -48,10 +41,12 @@
4841
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
4942
import fr.free.nrw.commons.utils.LocationUtils;
5043
import fr.free.nrw.commons.utils.UiUtils;
44+
import java.util.ArrayList;
45+
import java.util.HashMap;
46+
import java.util.List;
47+
import javax.inject.Inject;
5148
import timber.log.Timber;
5249

53-
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
54-
5550
/**
5651
* Support Fragment wrapper around a map view.
5752
* <p>
@@ -315,24 +310,31 @@ public void updateMapToTrackPosition(LatLng curLatLng) {
315310
*/
316311
@Override
317312
public void addCurrentLocationMarker(LatLng curLatLng) {
318-
removeCurrentLocationMarker();
319-
Timber.d("Adds current location marker");
320-
321-
Icon icon = IconFactory.getInstance(getContext()).fromResource(R.drawable.current_location_marker);
322-
323-
MarkerOptions currentLocationMarkerOptions = new MarkerOptions()
324-
.position(new com.mapbox.mapboxsdk.geometry.LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()));
325-
currentLocationMarkerOptions.setIcon(icon); // Set custom icon
326-
currentLocationMarker = mapboxMap.addMarker(currentLocationMarkerOptions);
327-
328-
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = UiUtils.createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
329-
curLatLng.getAccuracy() * 2, 100);
330-
331-
PolygonOptions currentLocationPolygonOptions = new PolygonOptions()
332-
.addAll(circle)
333-
.strokeColor(getResources().getColor(R.color.current_marker_stroke))
334-
.fillColor(getResources().getColor(R.color.current_marker_fill));
335-
currentLocationPolygon = mapboxMap.addPolygon(currentLocationPolygonOptions);
313+
if (null != curLatLng) {
314+
removeCurrentLocationMarker();
315+
Timber.d("Adds current location marker");
316+
317+
Icon icon = IconFactory.getInstance(getContext())
318+
.fromResource(R.drawable.current_location_marker);
319+
320+
MarkerOptions currentLocationMarkerOptions = new MarkerOptions()
321+
.position(new com.mapbox.mapboxsdk.geometry.LatLng(curLatLng.getLatitude(),
322+
curLatLng.getLongitude()));
323+
currentLocationMarkerOptions.setIcon(icon); // Set custom icon
324+
currentLocationMarker = mapboxMap.addMarker(currentLocationMarkerOptions);
325+
326+
List<com.mapbox.mapboxsdk.geometry.LatLng> circle = UiUtils
327+
.createCircleArray(curLatLng.getLatitude(), curLatLng.getLongitude(),
328+
curLatLng.getAccuracy() * 2, 100);
329+
330+
PolygonOptions currentLocationPolygonOptions = new PolygonOptions()
331+
.addAll(circle)
332+
.strokeColor(getResources().getColor(R.color.current_marker_stroke))
333+
.fillColor(getResources().getColor(R.color.current_marker_fill));
334+
currentLocationPolygon = mapboxMap.addPolygon(currentLocationPolygonOptions);
335+
} else {
336+
Timber.d("not adding current location marker..current location is null");
337+
}
336338
}
337339

338340
@Override

0 commit comments

Comments
 (0)