As a vehicle moves on road, I capture lat/lons. I want to calculate the distance the vehicle traveled between each reported LatLon.
Let me mimic your use case with scenario of calculating distance that was made by hurricane Maria in 2017
Below query "prepares" data for this (BigQuery Standard SQL):
#standardSQL
WITH points AS (
SELECT ROW_NUMBER() OVER(ORDER BY iso_time) pos,
ST_GEOGPOINT(longitude, latitude) AS point
FROM `bigquery-public-data.noaa_hurricanes.hurricanes`
WHERE name LIKE '%MARIA%' AND season = '2017'
AND ST_DWITHIN(ST_GEOGFROMTEXT('POLYGON((-179 26, -179 48, -10 48, -10 26, -100 -10.1, -179 26))'), ST_GEOGPOINT(longitude, latitude), 10)
), lines AS (
SELECT pos, ST_MAKELINE(LAG(point) OVER(ORDER BY pos), point) line
FROM points
)
SELECT pos, line
FROM lines
WHERE pos > 1
above can be visualized as
Now, below calculates the distance that hurricane "traveled"
#standardSQL
WITH points AS (
SELECT ROW_NUMBER() OVER(ORDER BY iso_time) pos,
ST_GEOGPOINT(longitude, latitude) AS point
FROM `bigquery-public-data.noaa_hurricanes.hurricanes`
WHERE name LIKE '%MARIA%' AND season = '2017'
AND ST_DWITHIN(ST_GEOGFROMTEXT('POLYGON((-179 26, -179 48, -10 48, -10 26, -100 -10.1, -179 26))'), ST_GEOGPOINT(longitude, latitude), 10)
), lines AS (
SELECT pos, ST_MAKELINE(LAG(point) OVER(ORDER BY pos), point) line
FROM points
)
SELECT SUM(ST_LENGTH(line)) path_length
FROM lines
WHERE pos > 1

Note: ST_LENGTH(geography_expression)
returns the total length in meters of the lines in the input GEOGRAPHY
You can read more about ST_LENGTH here
new google.maps.Polyline()
. developers.google.com/maps/documentation/javascript/examples/… – ABCmark accepted answer
by using the tick on the left of the posted answer, below the voting. See meta.stackexchange.com/questions/5234/… for why it is important! Also important tovote on answer
. Vote up answers that are helpful. ... You can check about what to do when someone answers your question - stackoverflow.com/help/someone-answers. Following these simple rules you increase your own reputation score and at the same time you keep us motivated to answer your questions :o) please consider! – Mikhail Berlyant