1

I try to implement a GPS tracking service for my application. I've a service to push geolocation data into mongodb which works very well. Problem is that each vehicle must send a data in each 20 seconds.

As a requirement i should show the latest 24 hours data in google maps which makes a problem to receive a huge data set. (4320 for one vehicle). Is there any best practice in mongo or google maps to receive less data and show a line as the history? (Response is "json")

1 Answer 1

1

I assume your JSON looks like this:

{
  id: 42,
  car_id: 102,
  coordinates: [
    { lat: ..., lon: ..., timestamp: ... },
    { lat: ..., lon: ..., timestamp: ... },
    { lat: ..., lon: ..., timestamp: ... },
    ...
  ]
}

If you use JSON, the there are only 4 ways to reduce the size:

  1. Remove unused data

    1. You could remove duplicate entries from your list. If the car stands still for an hour, you will have 180 identical entries in a row. You could only keep a single one, because the drawn line on the map won't look different.

    2. Remove the timestamp if you don't need it. If the array is ordered, you might not need a timestamp for sorting.

  2. Shrink your data representation

    1. Each character makes a difference, if you've got 4320 entries. So you could replace for example lat and lon with x and y. That reduces the size by 4*4320 = 17280 characters.

    2. Change the representation. If you don't need the timestamp, you could simple reduce your data structure to coordinates: [[1,2],[3,4],[5,6],...] (where 1, 3 and 5 are the lat part and 2, 4, 6 are the lon part of the coordinate). This may reduce the JSON size by another 20-40%.

  3. Compress the data

    1. If possible use GZIP (or any other compression algorithm). That way you can easily shrink the JSON output to 10-20% of the original size.
  4. Use a more compact data format

    1. Have a look at Protocol Buffers (from Google). Spring supports it and there's also a JavaScript library.

    2. There are a few other protocols that can reduce the data size. I.e. Thrift (from Apache / Facebook), but I don't know if Spring / JavaScript supports it.

That's basically all you can do.

Sign up to request clarification or add additional context in comments.

Comments

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.