2

I am developing an Angular web service for creating photo journeys and displaying them on a map using Leaflet. When I upload the pictures, I get their coordinates from their EXIF data and their DateTimeOriginal from it which returns string like this:

enter image description here

and then save them in array for a further connecting with paths on a map.

I have issues with sorting this array by timestamps in order to connect the markers on the map properly:

enter image description here

How can I sort by time-stamp?

1

1 Answer 1

5

Seems that the dates are invalid. If it would be properly formatted like this ("2012/10/24 16:37:44") you might do this:

const a = new Date("2012/10/24 16:37:44").getTime();

For example, you would map over items in this array

function sortNumber(a,b) {
    return a - b;
}

items.map(item => new Date(item.timestamp).getTime()).sort(sortNumber);
Sign up to request clarification or add additional context in comments.

1 Comment

What I did is to replace the : in the time-stamp string and make it appropriate for parsing to a Date object, and then sorting the array by dates: sortMarkers() { this.currentMarkers.map(m => { let mTimestamp: string = m.timestamp.substring(0, 10); mTimestamp = mTimestamp.replace(/:/g, '-'); m.timestamp = mTimestamp + m.timestamp.substring(10); m.date = new Date(m.timestamp); }); this.currentMarkers = this.currentMarkers.sort(function (a, b) { return a.date - b.date; }); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.