Fix first time location get

This commit is contained in:
max-klaus 2021-01-20 10:38:57 +03:00
parent d416ef0a6a
commit 6417e995d3

View file

@ -349,17 +349,19 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (!settings.isLastKnownMapLocation()) { if (!settings.isLastKnownMapLocation()) {
// show first time when application ran // show first time when application ran
final WeakReference<MapActivity> activityRef = new WeakReference<>(this);
net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation(new OsmAndLocationListener() { net.osmand.Location location = app.getLocationProvider().getFirstTimeRunDefaultLocation(new OsmAndLocationListener() {
@Override @Override
public void updateLocation(Location location) { public void updateLocation(Location location) {
if (app.getLocationProvider().getLastKnownLocation() == null) { MapActivity a = activityRef.get();
setMapInitialLatLon(location); if (AndroidUtils.isActivityNotDestroyed(a) && app.getLocationProvider().getLastKnownLocation() == null) {
setMapInitialLatLon(a.mapView, location);
} }
} }
}); });
mapViewTrackingUtilities.setMapLinkedToLocation(true); mapViewTrackingUtilities.setMapLinkedToLocation(true);
if (location != null) { if (location != null) {
setMapInitialLatLon(location); setMapInitialLatLon(mapView, location);
} }
} }
addDialogProvider(mapActions); addDialogProvider(mapActions);
@ -384,7 +386,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
mIsDestroyed = false; mIsDestroyed = false;
} }
private void setMapInitialLatLon(@Nullable Location location) { private void setMapInitialLatLon(@NonNull OsmandMapTileView mapView, @Nullable Location location) {
if (location != null) { if (location != null) {
mapView.setLatLon(location.getLatitude(), location.getLongitude()); mapView.setLatLon(location.getLatitude(), location.getLongitude());
mapView.setIntZoom(14); mapView.setIntZoom(14);