1

I have a web application where each user also has GPS coordinates (SqlGeography). As of now, I calculate the distance between two GPS coordinates as Euclidean distance with the Distance function.

Some users have requested that I replace the approximated distance (in terms of air-line distance) with a more realistic distance. I'm thinking about using specific routing APIs (e.g., from Google, Here or Azure) to get a more realistic distance, for instance for a car ride.

Currently, I have approximately 5000 different GPS coordinates and I would like to calculate and store a pair-wise distance for all of these pairs. This would result in 5000 * 5000 queries / requests which is very expensive. Is there any way how I can reduce the quadratic complexity with a trick I haven't thought of?

citronas
  • 19,035
  • 27
  • 96
  • 164

1 Answers1

0

Some APIs have an option to add waypoints/stops between start and end of a route( i.e. Sygic web API.

Maybe Google and Co. do something similar.

Response includes legs property, representing route/duration from start to waypoint1, wapoint1 to waypointN, waypointN to end of route ... etc.

{
    "routes": [
        {
            "route": "oupjIa}w|@^ErCUPELEf@@`A[nAjGlBnFfBtERl@~DdNdA~DdBjG|BhKfArELbAd@`EJdFKxF?rBVfKF~BFjH@jEChJC`DMtLCzEApB@bIRdOZlGdAtLr@tErAxGnIj\\fBnIrBxMr@|Gh@fHf@jJPvFDvAHxBBf@X|EA`Br@zLd@|Dz@hF`AzElBhIvClMnA|Ib@dGd@bKb@rYBbBJ|CDxGFjEx@tm@N`ID|CF`PStMI|B[`Hi@vIcA`KkC|PcBtIoBlIaF`RgN~c@oGpTqGrWaFtWyEd\\mAlKcBpQkBbX{@~PcAlYG`CClAEdBAj@KdEe@z`@AlBCjDC|XJ~WTrTh@rWZ`Pf@tUTfK`@fQ|@d]v@|O|BpYhBpOrE`\\bC`RDZf@fEvBlULtBZfFJhBNxCBZn@xQ\\~TZb`@JxQ@jNO~PeAfa@mDzdAo@jOsArSmDx_@eAnK}AlRs@zNg@rRChUB|ENzKZnR~B~tAvBthAv@nUtAdWbCl\\p[zbDrFhh@nDvZdB`Mb@~C|@xGrJ~n@fIzb@pBlJv@lDzAxGrDtOzEnQ|Rdr@|FzU|ArH|DfU~ArLx@xG^dDtBbQb@nDhAtIFf@\\`CZvBDXbAbHDXbBvKv@`E|BfJd@~BVlAJh@tA~Gb@tB\\~AtDbPrB~IxB~IzB`JvCdLzAdGjAvELb@Nn@|@xDR~@r@jDzAjI`@hCT~AhDbVF\\fAjIlBbOrAlKjAtIr@lFz@nG@JJv@v@`G`@|Cd@jDDhAJp@D^TzB@ZBpCStEYfB_@pAeAlCINo@~@oBbBoCrAaFfB_H`BsGhA}Ch@gMrB}Bd@oAR_APyOlCwAV}EdASF]JcErA_BXe@G]w@EsBNu@l@yBZe@j@]f@GjBTx@JXF@kApAc]ImEO_AWq@uAkAgAe@eCyA_CoDm@s@cA[eCM?mIYiBsAcEy@uBcA}A]MeAGu@?e@VsEVw@Ho@JiBHwAEa@SaAKy@Cs@PuAlAc@r@sChE{CjFkA`D}AbGIj@y@bEW`Ai@rAw@tA",
            "eta": 1531834797,
            "duration": {
                "value": 1713,
                "text": "28 minutes 33 seconds"
            },
            "distance": {
                "value": 36430,
                "text": "36.43 km"
            },
            "legs": [
                {
                    "distance": {
                        "value": 36430,
                        "text": "36.43 km"
                    },
                    "duration": {
                        "value": 1713,
                        "text": "28 minutes 33 seconds"
                    },
                    "start_location": {
                        "latitude": 54.32168,
                        "longitude": 10.12193
                    },
                    "end_location": {
                        "latitude": 54.30731,
                        "longitude": 9.66195
                    },
                    "route": "oupjIa}w|@^ErCUPELEf@@`A[nAjGlBnFfBtERl@~DdNdA~DdBjG|BhKfArELbAd@`EJdFKxF?rBVfKF~BFjH@jEChJC`DMtLCzEApB@bIRdOZlGdAtLr@tErAxGnIj\\fBnIrBxMr@|Gh@fHf@jJPvFDvAHxBBf@X|EA`Br@zLd@|Dz@hF`AzElBhIvClMnA|Ib@dGd@bKb@rYBbBJ|CDxGFjEx@tm@N`ID|CF`PStMI|B[`Hi@vIcA`KkC|PcBtIoBlIaF`RgN~c@oGpTqGrWaFtWyEd\\mAlKcBpQkBbX{@~PcAlYG`CClAEdBAj@KdEe@z`@AlBCjDC|XJ~WTrTh@rWZ`Pf@tUTfK`@fQ|@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