elad661 / curlbus

Terminal based UI for Israeli public transit data
41 stars 7 forks source link

[enhancement] Find nearby stations #17

Closed guysoft closed 6 years ago

guysoft commented 6 years ago

Is this a request for help?: yes


Is this a BUG REPORT or FEATURE REQUEST? (choose one): FEATURE REQUEST

Orchestrator and version (e.g. Kubernetes, DC/OS, Swarm) None

Anything else we need to know: I want to build a kiosk that would display nearby buses in a given radius. For that I need a way to get GPS coordinates, and from them return a list of bus stations. Then I can pull them with curlbus.

The stations gps data is available here and is updated daily. The reason I think this should be in curlbus is because its 177MB to download and update, and it seems an external service should do it, or at least an instance of curlbus (if you want your privacy).

elad661 commented 6 years ago

I thought about it and I'm going to implement an API endpoint that will receive coordinates + radius in meters, and will return codes of all stops within this radius.

I might also add an option to query multiple stops at the same time, to minimize necessary round trips for refreshing the dashboard.

The frontend application will need to query the nearby stops, cache the result, and use it to occasionally query all nearby stops.

Both these endpoints will have limitations for performance reasons and more efficient server side caching:

elad661 commented 6 years ago

I implemented the nearby stop query endpoint, and it'll be live on curlbus.app soon.

b9008e47cbdf162ec96813559cf31ebe959ef972

Send a query to /nearby?lat={lat}&lon={lon}&radius={radius_in_meters}

Radius can be be 5 meters, 10 meters, 50 meters, and then up to 1000 meters at 50m increments. This limitation is put in place to avoid cache bloat.

This endpoint returns a list of dicts, each dict containing the stop code, translated stop name, and stop location

I haven't implemented querying multiple stops on the same request yet, but I'll get there. I think you can start implementing your dashboard now and query the listed stop codes in series.

guysoft commented 6 years ago

Cool! I also implemented it here locally yesterday, but with math and not geopy. I noticed you might want to return the distance well, because if a line passes in two stations, you want to return only the closest one.

elad661 commented 6 years ago

372ad965d78c3b66964681b2a5114cdd01d459b5 - done, distance is now returned for each stop in the returned list.