Center the map on the current location only on demand.
This commit is contained in:
parent
c1810d6b12
commit
4ec09c61d3
|
|
@ -16,8 +16,11 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.DragEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
|
@ -76,6 +79,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
private Button start_stop_trace;
|
||||
private Button start_stop_dog_trace;
|
||||
private Button add_object;
|
||||
private Button center_button;
|
||||
private TextView textViewCurrentLocation;
|
||||
|
||||
private MyLocation lastLocation = null;
|
||||
|
|
@ -116,6 +120,24 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
// Add the ability to zoom with 2 fingers
|
||||
map.setBuiltInZoomControls(false);
|
||||
map.setMultiTouchControls(true);
|
||||
map.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
map.onTouchEvent(motionEvent);
|
||||
if (mLocationOverlay != null) {
|
||||
mLocationOverlay.disableFollowLocation();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
center_button = findViewById(R.id.center_button);
|
||||
center_button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mLocationOverlay.enableFollowLocation();
|
||||
}
|
||||
});
|
||||
|
||||
// Center the map on a lat/lon
|
||||
IMapController mapController = map.getController();
|
||||
|
|
@ -498,7 +520,9 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
MyLocation loc = serviceGps.getCurrentLocation();
|
||||
if (loc != null) {
|
||||
GeoPoint currentPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||
if (mLocationOverlay.isFollowLocationEnabled()) {
|
||||
map.getController().setCenter(currentPoint);
|
||||
}
|
||||
if (serviceGps.isTraceurActivated()) {
|
||||
updateTrailTrace();
|
||||
if (lastLocation != null) {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@
|
|||
|
||||
</org.osmdroid.views.MapView>
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/center_button"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="top|end"
|
||||
android:layout_marginTop="90dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:background="@drawable/osm_ic_center_map" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
Loading…
Reference in New Issue