diff options
| author | Keith Packard <keithp@keithp.com> | 2013-04-13 12:13:18 -0700 |
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-04-13 12:13:18 -0700 |
| commit | 3cd8ff18a7546c1e251747ba26240cb130003ef1 (patch) | |
| tree | c02d8b775d91ca828c7cb3092bed363f62c00f99 /altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java | |
| parent | 192bc28fbe2a8613d0b42e4fb3f7674a1a50abc7 (diff) | |
altosdroid: Update UI even if no telem has been received. Center map.
This allows the receiver location to be displayed even when telemetry
is not.
Center the map on the first valid location, either receiver or
rocket. Update center if a significantly more precise location is received.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java')
| -rw-r--r-- | altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java index 29696dbf..66669ad0 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java @@ -60,6 +60,8 @@ public class TabMap extends Fragment implements AltosDroidTab { private TextView mReceiverLatitudeView; private TextView mReceiverLongitudeView; + private double mapAccuracy = -1; + @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -118,7 +120,6 @@ public class TabMap extends Fragment implements AltosDroidTab { mMap.setMyLocationEnabled(true); mMap.getUiSettings().setTiltGesturesEnabled(false); mMap.getUiSettings().setZoomControlsEnabled(false); - mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.8,-104.7),8)); mRocketMarker = mMap.addMarker( // From: http://mapicons.nicolasmollet.com/markers/industry/military/missile-2/ @@ -144,35 +145,52 @@ public class TabMap extends Fragment implements AltosDroidTab { } } - public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { - if (state.from_pad != null) { - mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); - mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); + private void center(double lat, double lon, double accuracy) { + if (mapAccuracy < 0 || accuracy < mapAccuracy/10) { + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lon),14)); + mapAccuracy = accuracy; } - if (state.gps != null) { - mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); - mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + } + public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) { + if (state != null) { + if (state.from_pad != null) { + mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance)); + mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing)); + } + if (mapLoaded) { + if (state.gps != null) { + mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon)); + mRocketMarker.setVisible(true); + + mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon))); + mPolyline.setVisible(true); + } + + if (state.state == AltosLib.ao_flight_pad) { + mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon)); + mPadMarker.setVisible(true); + } + } + if (state.gps != null) { + mTargetLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S")); + mTargetLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E")); + if (state.gps.locked && state.gps.nsat >= 4) + center (state.gps.lat, state.gps.lon, 10); + } } if (receiver != null) { + double accuracy; + + if (receiver.hasAccuracy()) + accuracy = receiver.getAccuracy(); + else + accuracy = 1000; mReceiverLatitudeView.setText(AltosDroid.pos(receiver.getLatitude(), "N", "S")); mReceiverLongitudeView.setText(AltosDroid.pos(receiver.getLongitude(), "W", "E")); + center (receiver.getLatitude(), receiver.getLongitude(), accuracy); } - if (mapLoaded) { - if (state.gps != null) { - mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon)); - mRocketMarker.setVisible(true); - - mPolyline.setPoints(Arrays.asList(new LatLng(state.pad_lat, state.pad_lon), new LatLng(state.gps.lat, state.gps.lon))); - mPolyline.setVisible(true); - } - - if (state.state == AltosLib.ao_flight_pad) { - mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon)); - mPadMarker.setVisible(true); - } - } } } |
