BusTrackDC-old icon indicating copy to clipboard operation
BusTrackDC-old copied to clipboard

Track actual bus locations

Open j-ro opened this issue 11 years ago • 5 comments

Not sure if WMATA publishes this data, and would involve different pin styles in the mapkit plugin, but would be cool if we could track actual buses on the roads.

j-ro avatar Feb 27 '13 15:02 j-ro

They do in fact! An example URL request would look like this: http://api.wmata.com/Bus.svc/json/jBusPositions?routeId=10A&includingVariations=true&lat=0&lon=0&radius=0&api_key={key}

The response body looks like this: { "BusPositions": [{ "DateTime": "2013-03-01T15:37:04", "Deviation": "-2.07", "DirectionNum": "1", "DirectionText": "SOUTH", "Lat": 38.792793, "Lon": -77.049606, "RouteID": "10A", "TripEndTime": "2013-03-01T15:35:00", "TripHeadsign": "HUNTING POINT", "TripID": "20383_11", "TripStartTime": "2013-03-01T14:53:00", "VehicleID": "2173" }] }

ITSoFRISCHial avatar Mar 01 '13 20:03 ITSoFRISCHial

Very cool! Now I have to figure out how to extend the Cordova MapKit plugin to do other types of annotations besides pins (like, say, a little bus icon) and we'd be in business!

j-ro avatar Mar 01 '13 21:03 j-ro

Never used Cordova before but when I get a chance I'll dive into your code to see how I can help.

ITSoFRISCHial avatar Mar 01 '13 21:03 ITSoFRISCHial

Cool! I'm assuming what you'll want to extend is this file:

https://github.com/j-ro/WheresTheBusDC/blob/master/WheresTheBusDC/Plugins/MapKit.m

And maybe MapKit.h, too. Objective-C is not my strong suit...

But basically what we'd need is a function similar to the one that's there to create pins, which allows me to build a pin array like this:

pins.push(
            {
                lat: [latitude of my pin],
                lon: [latitude of my pin],
                title: [title of my pin when tapped],
                pinColor: "green", [<-- maybe this is replaced by a link to an image? or some variable that refers to an objective-C image that we assign, like a little bus icon?]
                selected: false, [<-- choose whether or not the pin drops and immediately selects, I always say false]
                index: i [<-- I don't use this...]
            }
        );

And then drop the pins on the map like this:

window.plugins.mapKit.addMapPins(pins);

And clear them like this:

window.plugins.mapKit.clearMapPins();

So, if we have a version that was addMapIcons and clearMapIcons that dealt with these icons, that would do it I think!

j-ro avatar Mar 01 '13 22:03 j-ro

The above code is all javascript, BTW -- probably obvious, but worth clarifying. So the plugin takes those javascript functions/data and turns them into objective-C somehow and displays them on the native map.

j-ro avatar Mar 01 '13 22:03 j-ro