Geolocation accuracy improvement for vehicle tracking
Basic GPS and Google Map APIs for better render of moving vehicles
Overview
Global Position System (GPS) is a satellite-based navigation system operated by the United States Air Force which provide the geolocation, time and derived velocity where there is an unobstructed line of sight to four or more GPS satellites with the accuracy ranging from 100ft to 15ft (30m - 4.5m) radius.
For instance, mobile phone utilizes Assisted GPS (A-GPS) from telecommunication tower cells to speed up the triangulation process and provide a better result of the actual location. With Google Maps, the live geolocation can be displayed and even broadcasted in real-time with the help of already collected geography data to place the vehicle’s position onto the correct path via Google Map SnapToRoad API.
Ultimately, the goal for this type of application is to ensure the trajectory of moving vehicles is correct, i.e. moving on roads and provide better user experiences.
Side note: Read more about Third Generation GPS upcoming launch by the United States Air Force collaborate with SpaceX and their Falcon 9 rocket.
Prerequisite
Follow the official documentations to setup your Google account and create a Google Cloud Platform Project with Billing Enabled.
Google Free Tier introduces a 12 months, $300 trial 1 for new user to learn the basics with several limitations which will not be an issue for our setup.
Well ! To be perfectly candid, it does depend on how much requests you invoke for your map display, so make sure to verify it and there are options to limit user request or malicious attempt to work up your bill.
If you have already setup your Google Maps Java API, well done ! Skip to the second part of the tutorial for instruction on how SnapToRoad API work or read more about how GPS data from the satellite can be interpreted.
GPS Information Standard
The National Marine Electronics Association (NMEA) has developed a specification that defines the interface between various pieces of marine electronic equipment. Their standard permits geo-positioning electronics to send information to computers and to other marine equipment.
NMEA Sentences
GPS receiver communication is defined within this specification with the idea is to send a line of data called an NMEA sentence that describes essential piece of information that was pre-defined for sets of sentence and serving multi-purposes.

Similarly, an analysis of another commonly used NMEA sentence can be found tabulated as below.

See full list of GPS receivers sentences (NMEA 2.0 Standard)
{% highlight ruby %} AAM - Waypoint Arrival Alarm ALM - Almanac data APA - Auto Pilot A sentence APB - Auto Pilot B sentence BOD - Bearing Origin to Destination BWC - Bearing using Great Circle route DTM - Datum being used. GGA - Fix information GLL - Lat/Lon data GRS - GPS Range Residuals GSA - Overall Satellite data GST - GPS Pseudorange Noise Statistics GSV - Detailed Satellite data MSK - send control for a beacon receiver MSS - Beacon receiver status information. RMA - recommended Loran data RMB - recommended navigation data for gps RMC - recommended minimum data for gps RTE - route message TRF - Transit Fix Data STN - Multiple Data ID VBW - dual Ground / Water Spped VTG - Vector track an Speed over the Ground WCV - Waypoint closure velocity (Velocity Made Good) WPL - Waypoint Location information XTC - cross track error XTE - measured cross track error ZTG - Zulu (UTC) time and time to go (to destination) ZDA - Date and Time {% endhighlight %}
Geolocation Stream
The initial step to get GPS data took place in simulation environment for a better understanding of the NMEA sentences, specifically tailored for the GPS Receiver, i.e. GPRMC, GPGGA and etc.

In actual implementation, the similar set of strings (line of data) can also be found.

SnapToRoad API
Application Programming Interface (API) acting as a medium between different programming languages, platforms and hence the name. That is, the Google Map API provides a convenience approach to utilizes the geography data that are necessary to correctly identify the roads without too much hassle.
Syntax Explanation
With Google Map Java API enabled, the SnapToRoad specifically can be invoked using HTTP Request. The result is a similar set of data, with the points snapped to the most likely roads the vehicle was traveling along.
https://roads.googleapis.com/v1/snapToRoads?parameters&key=YOUR_API_KEY
The required parameters include the path
, i.e. latitude/longitude pair divided by the character |
and obviously your API_Key
. For instance, a set of three coordinates with optional flag interpolate
enabled in complete HTTP request form as below.
https://roads.googleapis.com/v1/snapToRoads?path=10.7768936,106.6999664|10.7781286,106.6987686|10.7787838,106.6979217|10.7799883&interpolate=true&key=xxxxxxxxx
NOTE: As of August 2018, Google introduces new Pricing Plan for their product including Roads API.
Compared Results
The below results are indication of three different implementation including Raw Geolocation, Filtered Digitally, Roads API displayed using Google MyMap and were tested under two opposite scenarios, i.e. freeway express and downtown centre.

The main target for geographically monitoring a large amount of vehicles is usually resided in urban area where it is crowed with enormous wireless data transmission and signals bounced off tall buildings as well as other potential interference.

NOTE: This comparison is relative with only points and using an embedded GPS receiver instead of mobile phone which would have been better in term of performance as previously discussed.
Troubleshooting (Extra)
- Authorization issues with API Key
Head to Google API Console for Developer and select your project.
Then hit Tab APIs
Under Enabled APIs select Roads API
Select Credentials
sub-menu and request for new API Key. Similar instruction for Cloud Console in another article.