codeforamerica / openbus-api

http://api.chab.us
ISC License
17 stars 6 forks source link

"Nearby" endpoint #11

Open jeremiak opened 10 years ago

jeremiak commented 10 years ago

We'd like to build an app that uses the inputted address or the device GPS coordinates to find stops within a 0.5 mile radius. For each stop, the ideal information to be returned would be:

  1. The stop name/address
  2. Distance from supplied location
  3. Bus routes that service it and their final stops in each direction
  4. When the next 3 buses on each of those routes in each direction will arrive at that stop
seabre commented 10 years ago

Took a quick look, and it looks like you can grab the coordinates for each stop from this route: http://bustracker.gocarta.org/bustime/map/getRoutePoints.jsp?route=9&key=0.032425438752397895

The route param is the number assigned to each bus route. Not sure what the key param is for yet.

junosuarez commented 10 years ago

@seabre key is an api key.

The plan is to grab all the route points and index them using a terraformer geostore

From stop, we can get which routes service it. In order to get next bus arrival time predictions we'd need to make another api call. I don't think it makes sense to always poll every stop - this sounds like a large load even for a system as small as Chattanooga. Better access to the underlying data would be ideal, but seems unlikely at this point.

junosuarez commented 10 years ago

Working on building this out.

proposed api endpoint: /stops/near?lat=35.064657&lon=274.689986?lat=35.064657&lon=274.689986

example response (pretty printed):


{
  "type": "FeatureCollection",
  "lenth": 12,
  "features": [
    {
      "type": "Feature",
      "id": "1688",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31017363071402,
          35.065837025297
        ]
      },
      "properties": {
        "name": "MANNING + SPEARS AVE",
        "routes": [
          {
            "id": "2",
            "direction": "OUT"
          }
        ]
      },
      "distance": 68
    },
    {
      "type": "Feature",
      "id": "735",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31020045280502,
          35.066912748408
        ]
      },
      "properties": {
        "name": "BUSH + SPEARS",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ]
      },
      "distance": 95
    },
    {
      "type": "Feature",
      "id": "736",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.310318470001,
          35.066069733947
        ]
      },
      "properties": {
        "name": "SPEARS + MANNING",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ]
      },
      "distance": 118
    },
    {
      "type": "Feature",
      "id": "738",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31042039394401,
          35.063597719473
        ]
      },
      "properties": {
        "name": "CHEROKEE + MANUFACTURERS",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ]
      },
      "distance": 151
    },
    {
      "type": "Feature",
      "id": "734",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.30911833333198,
          35.066948266426
        ]
      },
      "properties": {
        "name": "MARKET + BUSH",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ]
      },
      "distance": 333
    },
    {
      "type": "Feature",
      "id": "737",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31177222728701,
          35.064361724834
        ]
      },
      "properties": {
        "name": "CHEROKEE + MINOR",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ]
      },
      "distance": 641
    },
    {
      "type": "Feature",
      "id": "1458",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31181514263199,
          35.066025826705
        ]
      },
      "properties": {
        "name": "MANNING + MAY",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          },
          {
            "id": "2",
            "direction": "OUT"
          }
        ]
      },
      "distance": 658
    },
    {
      "type": "Feature",
      "id": "1689",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.311981,
          35.066666933118
        ]
      },
      "properties": {
        "name": "MAY + NORTH CHATTANOOGA  RECREATION CENTER",
        "routes": [
          {
            "id": "2",
            "direction": "OUT"
          }
        ]
      },
      "distance": 720
    },
    {
      "type": "Feature",
      "id": "739",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.307920575142,
          35.062548298154
        ]
      },
      "properties": {
        "name": "FRAZIER + WOODLAND",
        "routes": [
          {
            "id": "34",
            "direction": "OUT"
          }
        ]
      },
      "distance": 766
    },
    {
      "type": "Feature",
      "id": "1699",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.313231000001,
          35.065860933188
        ]
      },
      "properties": {
        "name": "MANNING + CHEROKEE",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ]
      },
      "distance": 1174
    },
    {
      "type": "Feature",
      "id": "716",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.30676722526601,
          35.062460479858
        ]
      },
      "properties": {
        "name": "FRAZIER + FORREST",
        "routes": [
          {
            "id": "16",
            "direction": "IN"
          },
          {
            "id": "34",
            "direction": "IN"
          }
        ]
      },
      "distance": 1186
    },
    {
      "type": "Feature",
      "id": "740",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.30675649642899,
          35.06237705239
        ]
      },
      "properties": {
        "name": "FRAZIER + FORREST",
        "routes": [
          {
            "id": "16",
            "direction": "OUT"
          },
          {
            "id": "34",
            "direction": "OUT"
          }
        ]
      },
      "distance": 1190
    }
  ]
}
junosuarez commented 10 years ago

@jeremiak working on adding bus prediction times this morning, although it will probably be in a separate endpoint than the (relatively static) "stops" endpoint.

The stop name/address Distance from supplied location Bus routes that service it and their final stops in each direction When the next 3 buses on each of those routes in each direction will arrive at that stop

We can get 1, 2, and 4, but 3 will have to wait until we have reliable GTFS data. Until then, we'll only know the available destinations of the upcoming buses. I'm also opting not to limit it to 3. Certain stops, eg the ones along the Market St bus mall, serve many buses/destinations. Also, the limit seems arbitrary, and the data is small.

junosuarez commented 10 years ago

Example output:


{
  "type": "FeatureCollection",
  "length": 12,
  "features": [
    {
      "type": "Feature",
      "id": "1688",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31017363071402,
          35.065837025297
        ]
      },
      "properties": {
        "name": "MANNING + SPEARS AVE",
        "routes": [
          {
            "id": "2",
            "direction": "OUT"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 7,
            "destination": "NORTH CHATTANOOGA",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 68
    },
    {
      "type": "Feature",
      "id": "735",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31020045280502,
          35.066912748408
        ]
      },
      "properties": {
        "name": "BUSH + SPEARS",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 17,
            "destination": "DOWNTOWN",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 95
    },
    {
      "type": "Feature",
      "id": "736",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.310318470001,
          35.066069733947
        ]
      },
      "properties": {
        "name": "SPEARS + MANNING",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 18,
            "destination": "DOWNTOWN",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 118
    },
    {
      "type": "Feature",
      "id": "738",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31042039394401,
          35.063597719473
        ]
      },
      "properties": {
        "name": "CHEROKEE + MANUFACTURERS",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 21,
            "destination": "DOWNTOWN",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 151
    },
    {
      "type": "Feature",
      "id": "734",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.30911833333198,
          35.066948266426
        ]
      },
      "properties": {
        "name": "MARKET + BUSH",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 17,
            "destination": "DOWNTOWN",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 333
    },
    {
      "type": "Feature",
      "id": "737",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31177222728701,
          35.064361724834
        ]
      },
      "properties": {
        "name": "CHEROKEE + MINOR",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 20,
            "destination": "DOWNTOWN",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 641
    },
    {
      "type": "Feature",
      "id": "1458",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.31181514263199,
          35.066025826705
        ]
      },
      "properties": {
        "name": "MANNING + MAY",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          },
          {
            "id": "2",
            "direction": "OUT"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 7,
            "destination": "NORTH CHATTANOOGA",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 658
    },
    {
      "type": "Feature",
      "id": "1689",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.311981,
          35.066666933118
        ]
      },
      "properties": {
        "name": "MAY + NORTH CHATTANOOGA  RECREATION CENTER",
        "routes": [
          {
            "id": "2",
            "direction": "OUT"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 7,
            "destination": "NORTH CHATTANOOGA",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 720
    },
    {
      "type": "Feature",
      "id": "739",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.307920575142,
          35.062548298154
        ]
      },
      "properties": {
        "name": "FRAZIER + WOODLAND",
        "routes": [
          {
            "id": "34",
            "direction": "OUT"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 15,
            "destination": "TREMONT + FRAZIER",
            "vehicle": "34",
            "route": "34"
          }
        ]
      },
      "distance": 766
    },
    {
      "type": "Feature",
      "id": "1699",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.313231000001,
          35.065860933188
        ]
      },
      "properties": {
        "name": "MANNING + CHEROKEE",
        "routes": [
          {
            "id": "2",
            "direction": "IN"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 19,
            "destination": "DOWNTOWN",
            "vehicle": "2",
            "route": "2"
          }
        ]
      },
      "distance": 1174
    },
    {
      "type": "Feature",
      "id": "716",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.30676722526601,
          35.062460479858
        ]
      },
      "properties": {
        "name": "FRAZIER + FORREST",
        "routes": [
          {
            "id": "16",
            "direction": "IN"
          },
          {
            "id": "34",
            "direction": "IN"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 0,
            "destination": "SHUTTLE PARK NORTH",
            "vehicle": "34",
            "route": "34"
          },
          {
            "minutesAway": 24,
            "destination": "DOWNTOWN",
            "vehicle": "16",
            "route": "16"
          }
        ]
      },
      "distance": 1186
    },
    {
      "type": "Feature",
      "id": "740",
      "geometry": {
        "type": "Point",
        "coordinates": [
          -85.30675649642899,
          35.06237705239
        ]
      },
      "properties": {
        "name": "FRAZIER + FORREST",
        "routes": [
          {
            "id": "16",
            "direction": "OUT"
          },
          {
            "id": "34",
            "direction": "OUT"
          }
        ],
        "arrivals": [
          {
            "minutesAway": 15,
            "destination": "TREMONT + FRAZIER",
            "vehicle": "34",
            "route": "34"
          }
        ]
      },
      "distance": 1190
    }
  ]
}
junosuarez commented 10 years ago

Both of these endpoints are now available on the new staging (#12) environment:

I'm not sold on the naming of the /nearby route, and am open to suggestions.

Eventually I want to add a /nearby/tail route to receive streaming updates