https://github.com/jimlynchcodes/route-builder-5000
A JavaScript / TypeScript function that calculates the optimal route for a traveling salesman-esque type problem.
https://github.com/jimlynchcodes/route-builder-5000
Last synced: 4 months ago
JSON representation
A JavaScript / TypeScript function that calculates the optimal route for a traveling salesman-esque type problem.
- Host: GitHub
- URL: https://github.com/jimlynchcodes/route-builder-5000
- Owner: JimLynchCodes
- License: gpl-3.0
- Created: 2019-08-11T17:10:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-11T17:43:45.000Z (almost 7 years ago)
- Last Synced: 2025-07-24T12:48:58.136Z (11 months ago)
- Size: 16.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Route Builder 5000
### Playing With The Geolacation API's
Browers have pretty solid HTML5 support for geolation now. For example, you can open your console right in the browser and type this:
```
var g = navigator.geolocation.getCurrentPosition(g => {
console.log('got pos ', g);
return g
},err => {
console.log('didn't get pos ', err);
return b
} )
```
(Note: make sure to click "Allow" when you browser asks if you want to share your location).
This returns a "Position" object, containing a corrdinates object and a timestamp.
For example:
```
{
coords: {
accuracy: 82,
altitude: null
altitudeAccuracy: null
heading: null
latitude: 40.745938599999995
longitude: -73.99596989999999
speed: null
},
timestamp: 1565543870672
}
```
Since nyc is pretty flat, I think we can take altitude out of the equation and think about each location in terms of the latitude and longitude. Then it's not so much different from looking at the points as if they were x and y coordinates on a regular cartesian plane.
## The buildRoute Function
The core function that this service exposes would be called something like, "buildRoute", and as parameters it takes multiple destinations. However, things could be a bit more complicated than that. Here are some assumptions that I am making in the calculations here:
- The "current location" input represents where the person is physically standing at the current time.
- There can be an optional "inital destination" input. If supplied, the person must go here first.
- There can be an optional "final destination" input. If supplied, the person must end the route here.
- There can be an optional 0 or more "intermediate stops". If supplied, the person must visit all intermediate stops exactly once but in any order.
From the information above, we can conceive of a function that looks something like this:
```
static buildRoute( initialPersonLocation: Coordinates, intermediateDestinations?: Array, initalDestination?: Coordinates, finalDestion?: Coordinates) : RouteObject
```
The output RouteObject could have some information about the total route and then info about each destination.
example:
```
{
routeId: 'ASDFASDF',
totalLength: '1.1 miles',
numberOfDestionations: 5,
destionations: [{
name: "Target",
address: "123 Park Ave:,
distanceFromPrevious: '500ft',
distanceFromNext: '200ft',
thingsToGetThere: [{
...
}
},
...
]
}
```