|
1 | 1 | package fr.free.nrw.commons.nearby.fragments;
|
2 | 2 |
|
| 3 | +import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween; |
| 4 | + |
3 | 5 | import android.content.Context;
|
4 | 6 | import android.graphics.Bitmap;
|
5 | 7 | import android.os.Bundle;
|
6 | 8 | import android.util.AttributeSet;
|
7 | 9 | import android.view.LayoutInflater;
|
8 | 10 | import android.view.View;
|
9 | 11 | import android.view.ViewGroup;
|
10 |
| - |
11 | 12 | import androidx.annotation.NonNull;
|
12 | 13 | import androidx.annotation.Nullable;
|
13 | 14 | import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
14 |
| - |
15 | 15 | import com.mapbox.mapboxsdk.annotations.Icon;
|
16 | 16 | import com.mapbox.mapboxsdk.annotations.IconFactory;
|
17 | 17 | import com.mapbox.mapboxsdk.annotations.Marker;
|
|
26 | 26 | import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
27 | 27 | import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
28 | 28 | 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 |
| - |
36 | 29 | import fr.free.nrw.commons.R;
|
37 | 30 | import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
38 | 31 | import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
|
48 | 41 | import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
|
49 | 42 | import fr.free.nrw.commons.utils.LocationUtils;
|
50 | 43 | 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; |
51 | 48 | import timber.log.Timber;
|
52 | 49 |
|
53 |
| -import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween; |
54 |
| - |
55 | 50 | /**
|
56 | 51 | * Support Fragment wrapper around a map view.
|
57 | 52 | * <p>
|
@@ -315,24 +310,31 @@ public void updateMapToTrackPosition(LatLng curLatLng) {
|
315 | 310 | */
|
316 | 311 | @Override
|
317 | 312 | 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 | + } |
336 | 338 | }
|
337 | 339 |
|
338 | 340 | @Override
|
|
0 commit comments