diff --git a/src/store/actions.js b/src/store/actions.js
index facd49d..0dd26dd 100644
--- a/src/store/actions.js
+++ b/src/store/actions.js
@@ -112,18 +112,25 @@ export function setCurrentMapZoom({ commit, state }, { zoom }) {
}
export function setCurrentPosition(
- { commit, state },
- { accuracy = null, heading = null, latLng = null },
+ { commit, getters, state },
+ { coords, timestamp },
) {
- const locationState = state.location;
- if (
- accuracy !== locationState.accuracy ||
- heading !== locationState.heading ||
- locationState.currentLatLng.some((item, index) => item !== latLng[index])
- ) {
- // Throttle mutations if nothing has changed
- commit(SET_CURRENT_POSITION, { accuracy, heading, latLng });
- }
+ const currentLocation = {
+ latitude: coords.latitude,
+ longitude: coords.longitude,
+ hdop: coords.accuracy ? coords.accuracy : null,
+ elevation: coords.elevation ? coords.elevation : null,
+ vdop: coords.altitudeAccuracy ? coords.altitudeAccuracy : null,
+ heading: (
+ (coords.heading !== null && !isNaN(coords.heading))
+ ? coords.heading
+ : null
+ ),
+ speed: coords.speed ? coords.speed : null,
+ timestamp,
+ };
+
+ commit(SET_CURRENT_POSITION, { currentLocation });
}
export function setLocationWatcherId({ commit }, { id }) {
diff --git a/src/store/getters.js b/src/store/getters.js
index df6721a..a10065e 100644
--- a/src/store/getters.js
+++ b/src/store/getters.js
@@ -1,5 +1,13 @@
import { REPORT_VOTES_THRESHOLD } from '@/constants';
+export function getLastLocation(state) {
+ const gpx = state.location.gpx;
+ if (gpx.length > 0) {
+ return gpx[gpx.length - 1];
+ }
+ return null;
+}
+
export function notDismissedReports(state) {
return state.reports.filter((item) => {
if (item.attributes.downvotes === 0) {
diff --git a/src/store/mutations.js b/src/store/mutations.js
index e253ffd..ea18a0f 100644
--- a/src/store/mutations.js
+++ b/src/store/mutations.js
@@ -86,11 +86,8 @@ export const initialState = {
hasGoneThroughIntro: false,
isLoading: false,
location: {
- accuracy: null,
- currentLatLng: [null, null],
error: null,
- heading: null, // in degrees, clockwise wrt north
- positionHistory: [],
+ gpx: [],
watcherID: null,
},
map: {
@@ -161,11 +158,8 @@ export const mutations = {
[types.SET_CURRENT_MAP_ZOOM](state, { zoom }) {
Vue.set(state.map, 'zoom', zoom);
},
- [types.SET_CURRENT_POSITION](state, { accuracy, heading, latLng }) {
- Vue.set(state.location, 'accuracy', accuracy);
- Vue.set(state.location, 'currentLatLng', latLng);
- Vue.set(state.location, 'heading', heading);
- state.location.positionHistory.push(latLng);
+ [types.SET_CURRENT_POSITION](state, { currentLocation }) {
+ state.location.gpx.push(currentLocation);
},
[types.SET_LOCATION_ERROR](state, { error }) {
Vue.set(state.location, 'error', error);
diff --git a/src/tools/index.js b/src/tools/index.js
index b7491c5..eea1838 100644
--- a/src/tools/index.js
+++ b/src/tools/index.js
@@ -38,6 +38,7 @@ export function mockLocation() {
longitude: (Math.random() * (LNG_MAX - LNG_MIN)) + LNG_MIN,
heading: null, // 20 * (Math.PI / 180),
},
+ timestamp: new Date().getTime(),
};
console.log('New mock location: ', newLocation);
return newLocation;
diff --git a/src/views/Map.vue b/src/views/Map.vue
index b8beb7d..bcaef92 100644
--- a/src/views/Map.vue
+++ b/src/views/Map.vue
@@ -4,9 +4,9 @@