Reputation: 934
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")
Upvotes: 1
Views: 352
Reputation: 24527
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:
Remove unused data
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.
Remove the timestamp
if you don't need it. If the array is ordered, you might not need a timestamp for sorting.
Shrink your data representation
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.
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%.
Compress the data
Use a more compact data format
Have a look at Protocol Buffers (from Google). Spring supports it and there's also a JavaScript library.
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.
Upvotes: 1