A-GPS Tracker

An App to record Breadcrumb trails

R Batzinger

Basic Operation

  • A-GPS Tracker monitors position and altitude using the GPS capabilities of your phone.

  • Once started, the monitoring occurs at a constant rate of time 1pt per 5 sec (provided that there is movement).

  • It stays active even despite phone stand-by mode or use of other applications (increasing power consumption).

  • Google background maps when the device is online. (Open Street Map version is available)

Functions

  1. Provide altimeter readings when using GPS

  2. Path following mode to keep on a path

  3. Can use location data from: American GPS, GLONASS, BeiDou Galileo, cellphone towers and wifi

  4. Exports data as GPX standard

Common indicators and functions

Indicators Functions
GPS lock Achieved Switch on previous track
Compass North Arrow GPX File management
GPS quality GPS Control
Map Type Selector Center the Map
Elevation Photograph GIS
Off-track alarm Track Recorder Function
Progress along path Add point of interest

Advance features

  • Photograph location
  • Offline background maps
  • Advance recording control
  • Rejection of GPS deviant readings

Increasing reliability

A-GPS gives precise position and altitude under these conditions:1

  • open sky
  • phone antenna not obstructed by metallic objects
  • lack of buildings or mountains
  • fair weather conditions
  • Good GPS lock on 5 or more satellites

What is a GPX file?

  • An open XML format used for GPS Exchange
  • A data file is text-readable and can be interpreted with an XML parser
  • allows GPS data to be export, imported and read by multiple programs and web services.

Sample GPX file

    <link href="https://play.google.com/store/apps/details?id=com.ilyabogdanovich.geotracker" />
     <extensions>
       <geotracker:meta>
          <length>1438.32</length>
          <duration>351138</duration>
          <creationtime>2014-06-27T05:28:39.14Z</creationtime>
          <activity>0</activity>
       </geotracker:meta>
    </extensions>
    <trk>
      <trkseg>
        <trkpt lat="18.796236" lon="99.032867">
           <ele>273.7</ele>
          <time>2014-06-27T05:28:44.00Z</time>
          <extensions>
            <geotracker:meta s="0" />
          </extensions>
        </trkpt>
        <trkpt lat="18.796333" lon="99.032799">
          <ele>271</ele>
          <time>2014-06-27T05:29:21.00Z</time>
          <extensions>
            <geotracker:meta c="336" s="1.25" />
          </extensions>
        </trkpt>      
           ...
             
        </trkseg>
       </trk>
     </gpx>

Data stored in GPX files

  • Waypoint - Includes GPS coordinates of a point. It may also include other descriptive information.
  • Route - Includes a list of track points, which are waypoints for turn or stage points, that lead to a destination.
  • Track - Includes a list of points that describe a path.

Often combined by mapping and fitness applications to display key information along a route

Reading GPX files

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<gpx version="1.1" 
     xmlns="http://www.topografix.com/GPX/1/1"
     creator="Geo Tracker 2.0.1 for Android">
   <metadata>
     <name>Jun 27, 2014 12:28:39 PM</name>
     <author>Recorded in Geotracker for Android</author>
     <link href="https://play.google.com/store/apps/details?
         id=com.ilyabogdanovich.geotracker" />
     <time>2014-06-27T05:28:39.14Z</time>
   </metadata>
  <trk>
    <name>Jun 27, 2014 12:28:39 PM</name>
    <src>Recorded in Geotracker for Android</src>
    <link href="https://play.google.com/store/apps/details?
        id=com.ilyabogdanovich.geotracker" />
    <extensions>
      <geotracker:meta>
        <length>1438.32</length>
        <duration>351138</duration>
        <creationtime>2014-06-27T05:28:39.14Z</creationtime>
        <activity>0</activity>
      </geotracker:meta>
    </extensions>
    <trkseg>
      <trkpt lat="18.796236" lon="99.032867">
        <ele>273.7</ele>
        <time>2014-06-27T05:28:44.00Z</time>
        <extensions>
          <geotracker:meta s="0" />
        </extensions>
      </trkpt>
      <trkpt lat="18.796333" lon="99.032799">
        <ele>271</ele>
        <time>2014-06-27T05:29:21.00Z</time>
        <extensions>
          <geotracker:meta c="336" s="1.25" />
        </extensions>
      </trkpt>
       . . .
   </trkseg>
 </trk>
</gpx>

Installing R

  • Download and install the latest stable version of R

  • Download and install the latest stable version of RStudio

  • Add the following libraries to yor RStudio

    • Geosphere
    • leaflet
    • xml2
    • htmlwidgets

Examining the structure

::::{.columns} :::{.column width=“50%”}

library(xml2)
d = read_xml("2706141228.gpx")
xml_structure(d)

::: :::{.column width=“50%”}

Extracting the data points

library(xml2)
d <- read_xml("Jun_27,_2014_12_28_39_PM_1.gpx")
ddd = xml_children(xml_children(xml_children(d)[2])[5])
ddd
{xml_nodeset (89)}
 [1] <trkpt lat="18.796236" lon="99.032867">\n  <ele>273.7</ele>\n  <time>201 ...
 [2] <trkpt lat="18.796333" lon="99.032799">\n  <ele>271</ele>\n  <time>2014- ...
 [3] <trkpt lat="18.7964" lon="99.032883">\n  <ele>270.6</ele>\n  <time>2014- ...
 [4] <trkpt lat="18.796471" lon="99.032951">\n  <ele>269.7</ele>\n  <time>201 ...
 [5] <trkpt lat="18.796547" lon="99.033012">\n  <ele>270.4</ele>\n  <time>201 ...
 [6] <trkpt lat="18.79664" lon="99.033028">\n  <ele>270.3</ele>\n  <time>2014 ...
 [7] <trkpt lat="18.796764" lon="99.033012">\n  <ele>270.4</ele>\n  <time>201 ...
 [8] <trkpt lat="18.796888" lon="99.033005">\n  <ele>270.3</ele>\n  <time>201 ...
 [9] <trkpt lat="18.797064" lon="99.032967">\n  <ele>270.2</ele>\n  <time>201 ...
[10] <trkpt lat="18.797155" lon="99.032959">\n  <ele>270.3</ele>\n  <time>201 ...
[11] <trkpt lat="18.79731" lon="99.032928">\n  <ele>270.5</ele>\n  <time>2014 ...
[12] <trkpt lat="18.797466" lon="99.032898">\n  <ele>270.4</ele>\n  <time>201 ...
[13] <trkpt lat="18.797596" lon="99.032898">\n  <ele>270.5</ele>\n  <time>201 ...
[14] <trkpt lat="18.797724" lon="99.032928">\n  <ele>270.1</ele>\n  <time>201 ...
[15] <trkpt lat="18.797836" lon="99.032959">\n  <ele>271.1</ele>\n  <time>201 ...
[16] <trkpt lat="18.797993" lon="99.032883">\n  <ele>271.6</ele>\n  <time>201 ...
[17] <trkpt lat="18.798063" lon="99.032822">\n  <ele>273.4</ele>\n  <time>201 ...
[18] <trkpt lat="18.798147" lon="99.032768">\n  <ele>273.3</ele>\n  <time>201 ...
[19] <trkpt lat="18.798052" lon="99.032822">\n  <ele>272</ele>\n  <time>2014- ...
[20] <trkpt lat="18.797945" lon="99.032906">\n  <ele>272.1</ele>\n  <time>201 ...
...

Determining speed

\[Speed = \frac{distance}{time}\]

Spherical model of the globe:

\[distance = Haversine(loc1,loc2)\] Elliptical model of the globe:

\[distance = distVincentyEllipsoid(loc1,loc2)\]

library(geosphere)
point1 <- c(-73.935242, 40.730610)  # NY
point2 <- c(-118.243683, 34.052235) # LA

distance <- distHaversine(point1, point2)
print(distance)
[1] 3945982
print(distVincentyEllipsoid(point1,point2))
[1] 3950256

Converting GPX to a dataframe

library(xml2)
library(geosphere)
library(lubridate)

d <- read_xml("Jun_27,_2014_12_28_39_PM_1.gpx")
ddd = xml_children(xml_children(xml_children(d)[2])[5]) 
numpts = length(ddd) 
col = rep(0,numpts) 
pttab = as.data.frame(cbind(col,col,col,col))
colnames(pttab) = c("lat","lon","ele","timestamp")

for(i in 1:numpts){
  others = xml_children(ddd[i])
  pttab[i,1] = as.numeric(xml_attr(ddd[i],"lat"))
  pttab[i,2] = as.numeric(xml_attr(ddd[i],"lon"))
  pttab[i,3] = as.numeric(xml_text(others[1],"ele"))
  pttab[i,4] = xml_text(others[2],"time")
}
secs = c(1,c(ymd_hms(pttab[2:numpts,4])-ymd_hms(pttab[1:numpts-1,4])))
dist = c(0, distVincentyEllipsoid(
  cbind(pttab[2:numpts,2], pttab[2:numpts,1]),
  cbind(pttab[1:(numpts-1),2],pttab[1:(numpts-1),1])))
speed = round(3.6* dist/secs,5)
pttab = cbind(pttab,speed)

Waypoint DataFrame

lat lon ele timestamp speed
18.79624 99.03287 273.7 2014-06-27T05:28:44.00Z 0.00000
18.79633 99.03280 271.0 2014-06-27T05:29:21.00Z 1.25611
18.79640 99.03288 270.6 2014-06-27T05:29:32.00Z 3.78018
18.79647 99.03295 269.7 2014-06-27T05:29:40.00Z 4.78676
18.79655 99.03301 270.4 2014-06-27T05:29:48.00Z 4.76493
18.79664 99.03303 270.3 2014-06-27T05:30:07.00Z 1.97648
18.79676 99.03301 270.4 2014-06-27T05:30:10.00Z 16.59452
18.79689 99.03301 270.3 2014-06-27T05:30:12.00Z 24.74161
18.79706 99.03297 270.2 2014-06-27T05:30:13.00Z 71.60033
18.79716 99.03296 270.3 2014-06-27T05:30:14.00Z 36.38881
18.79731 99.03293 270.5 2014-06-27T05:30:16.00Z 31.43765
18.79747 99.03290 270.4 2014-06-27T05:30:18.00Z 31.59866
18.79760 99.03290 270.5 2014-06-27T05:30:20.00Z 25.90138
18.79772 99.03293 270.1 2014-06-27T05:30:22.00Z 26.13051
18.79784 99.03296 271.1 2014-06-27T05:30:25.00Z 15.38488
18.79799 99.03288 271.6 2014-06-27T05:30:28.00Z 22.96342
18.79806 99.03282 273.4 2014-06-27T05:30:33.00Z 7.24977
18.79815 99.03277 273.3 2014-06-27T05:30:36.00Z 13.08259
18.79805 99.03282 272.0 2014-06-27T05:31:00.00Z 1.79362
18.79794 99.03291 272.1 2014-06-27T05:31:03.00Z 17.74577
18.79783 99.03294 271.7 2014-06-27T05:31:06.00Z 16.14046
18.79771 99.03298 271.7 2014-06-27T05:31:09.00Z 16.90293
18.79745 99.03308 271.6 2014-06-27T05:31:11.00Z 54.35522
18.79733 99.03310 271.5 2014-06-27T05:31:13.00Z 24.86935
18.79640 99.03344 271.7 2014-06-27T05:31:30.00Z 23.00195
18.79635 99.03356 271.5 2014-06-27T05:31:32.00Z 25.36274
18.79632 99.03368 271.3 2014-06-27T05:31:34.00Z 22.24369
18.79589 99.03496 271.0 2014-06-27T05:31:55.00Z 24.60746
18.79583 99.03506 270.9 2014-06-27T05:31:56.00Z 44.74904
18.79576 99.03516 271.6 2014-06-27T05:31:59.00Z 14.91635
18.79575 99.03530 271.5 2014-06-27T05:32:02.00Z 18.39107
18.79569 99.03551 271.7 2014-06-27T05:32:07.00Z 16.37420
18.79569 99.03562 271.9 2014-06-27T05:32:09.00Z 21.86643
18.79581 99.03558 272.3 2014-06-27T05:32:10.00Z 50.05619
18.79600 99.03567 272.6 2014-06-27T05:32:13.00Z 27.87358
18.79609 99.03571 272.7 2014-06-27T05:32:14.00Z 36.59889
18.79628 99.03573 273.8 2014-06-27T05:32:16.00Z 39.07570
18.79637 99.03577 274.1 2014-06-27T05:32:18.00Z 19.03106
18.79649 99.03575 274.4 2014-06-27T05:32:22.00Z 11.85285
18.79658 99.03572 274.5 2014-06-27T05:32:25.00Z 12.92279
18.79670 99.03568 275.8 2014-06-27T05:32:28.00Z 16.52130
18.79679 99.03565 276.3 2014-06-27T05:32:30.00Z 19.06133
18.79690 99.03561 276.5 2014-06-27T05:32:32.00Z 23.64078
18.79705 99.03558 276.9 2014-06-27T05:32:34.00Z 29.38980
18.79721 99.03553 276.6 2014-06-27T05:32:36.00Z 34.20649
18.79732 99.03548 276.5 2014-06-27T05:32:37.00Z 47.92288
18.79749 99.03542 276.4 2014-06-27T05:32:39.00Z 35.41740
18.79761 99.03538 276.2 2014-06-27T05:32:40.00Z 50.02623
18.79775 99.03534 275.9 2014-06-27T05:32:41.00Z 58.87384
18.79787 99.03530 276.4 2014-06-27T05:32:42.00Z 47.28153
18.79801 99.03522 277.2 2014-06-27T05:32:43.00Z 65.29281
18.79813 99.03517 276.9 2014-06-27T05:32:44.00Z 50.41056
18.79823 99.03512 277.7 2014-06-27T05:32:45.00Z 45.87552
18.79832 99.03509 276.9 2014-06-27T05:32:46.00Z 36.86842
18.79848 99.03494 276.9 2014-06-27T05:32:48.00Z 42.41273
18.79854 99.03485 276.8 2014-06-27T05:32:49.00Z 42.54260
18.79863 99.03477 276.8 2014-06-27T05:32:50.00Z 46.02249
18.79871 99.03467 276.8 2014-06-27T05:32:51.00Z 52.12124
18.79880 99.03459 277.0 2014-06-27T05:32:52.00Z 44.79153
18.79887 99.03448 277.1 2014-06-27T05:32:53.00Z 50.95483
18.79895 99.03438 277.3 2014-06-27T05:32:54.00Z 49.79225
18.79895 99.03428 277.4 2014-06-27T05:32:55.00Z 37.57091
18.79898 99.03416 277.3 2014-06-27T05:32:56.00Z 46.06615
18.79899 99.03405 277.1 2014-06-27T05:32:57.00Z 43.35329
18.79904 99.03394 275.6 2014-06-27T05:32:58.00Z 47.30302
18.79905 99.03381 274.7 2014-06-27T05:32:59.00Z 49.41430
18.79911 99.03367 273.5 2014-06-27T05:33:00.00Z 56.89759
18.79913 99.03352 273.2 2014-06-27T05:33:02.00Z 28.07390
18.79915 99.03341 273.6 2014-06-27T05:33:04.00Z 22.05309
18.79910 99.03329 273.0 2014-06-27T05:33:07.00Z 15.76766
18.79909 99.03318 272.3 2014-06-27T05:33:10.00Z 14.64977
18.79901 99.03308 272.5 2014-06-27T05:33:15.00Z 9.70161
18.79895 99.03300 272.4 2014-06-27T05:33:19.00Z 10.14415
18.79887 99.03294 270.5 2014-06-27T05:33:22.00Z 12.34068
18.79874 99.03294 262.1 2014-06-27T05:33:25.00Z 17.56243
18.79864 99.03295 260.2 2014-06-27T05:33:28.00Z 13.02326
18.79855 99.03296 261.4 2014-06-27T05:33:33.00Z 7.59548
18.79845 99.03295 262.9 2014-06-27T05:33:41.00Z 4.59824
18.79835 99.03292 262.8 2014-06-27T05:33:46.00Z 8.36522
18.79833 99.03280 260.7 2014-06-27T05:33:54.00Z 5.86433
18.79838 99.03270 260.9 2014-06-27T05:33:58.00Z 10.28253
18.79849 99.03265 261.8 2014-06-27T05:34:02.00Z 12.18711
18.79860 99.03263 262.3 2014-06-27T05:34:05.00Z 15.52440
18.79874 99.03262 264.0 2014-06-27T05:34:08.00Z 17.63562
18.79884 99.03265 264.1 2014-06-27T05:34:11.00Z 14.45401
18.79889 99.03273 263.0 2014-06-27T05:34:15.00Z 9.34573
18.79888 99.03284 262.3 2014-06-27T05:34:19.00Z 10.21071
18.79882 99.03293 262.3 2014-06-27T05:34:24.00Z 8.13803
18.79874 99.03297 261.3 2014-06-27T05:34:28.00Z 9.33227

Naive Plot lat / lon

colors = rainbow(round(max(pttab[,5]))+1)
  plot(pttab[,2],pttab[,1],type="p",
       xlab="Longitude",ylab="Lattitude")
  lines(pttab[,2],pttab[,1])
  points(pttab[,2],pttab[,1],col=colors[round(pttab[,5]+1)],pch=19)

Drawing on Leaflet MAPS

library(leaflet)

leaflet() %>%
    addTiles() %>%
  addMarkers(lng = 174.768, lat = -36.852, popup = "Auckland")

Plot the data on a map

library(leaflet)
colors = rainbow(max(round(pttab[,5]))+1,alpha=1.0)
leaflet() %>% addTiles() %>%
  addPolylines(as.numeric(pttab[,2]),as.numeric(pttab[,1]),col="gray") %>%
  addCircles(lng=as.numeric(pttab[,2]),lat=pttab[,1],radius=5,color=colors[round(pttab[,5])+1]) 

Simple map HTML widget

library(leaflet)
library(htmlwidgets)

m <- leaflet() %>% 
  addTiles() %>% 
  addMarkers(lng = -71.0596, lat = 42.3581,
      popup = "Boston")

saveWidget(m, file = "my_map.html")

mapfile