Vamos a ver cómo empezar a trabajar con los servicios web que pone a nuestra disposición EMT Madrid.
En nuestro caso, queremos hacer sobre la Api de la EMT, un gestor muy sencillo, que tenga en cuenta, además, del tiempo estimado de al autobús a la parada, nuestro tiempo andando a varias paradas distintas, de cara a decidir hacia qué parada debemos caminar.
Toda la información de los métodos disponibles están en:
http://opendata.emtmadrid.es/Servicios-web/GEO
En nuestro caso, vamos a usar la llamada Get Arrive Stop con los números de parada.
Get Arrive Stop: https://openbus.emtmadrid.es:9443/emt-proxy-server/last/geo/GetArriveStop.php
El formato de respuesta es una lista de Arrives
{"arrives":[{"stopId":608,"lineId":"25","isHead":"False","destination":"CASA DE CAMPO","busId":"4063","busTimeLeft":0,"busDistance":0,"longitude":-3.7207142044687,"latitude":40.415443621459,"busPositionType":0},{"stopId":608,"lineId":"39","isHead":"False","destination":"SAN IGNACIO","busId":"4105","busTimeLeft":163,"busDistance":815,"longitude":-3.7319667753991,"latitude":40.412296871723,"busPositionType":1},{"stopId":608,"lineId":"25","isHead":"False","destination":"CASA DE CAMPO","busId":"4073","busTimeLeft":372,"busDistance":1604,"longitude":-3.7124736587359,"latitude":40.419499463385,"busPositionType":1},{"stopId":608,"lineId":"39","isHead":"False","destination":"SAN IGNACIO","busId":"4111","busTimeLeft":417,"busDistance":1833,"longitude":-3.7127886611517,"latitude":40.420772982078,"busPositionType":1},{"stopId":608,"lineId":"138","isHead":"False","destination":"ALUCHE","busId":"4182","busTimeLeft":537,"busDistance":2014,"longitude":-3.7112167000793,"latitude":40.423116470486,"busPositionType":1},{"stopId":608,"lineId":"33","isHead":"False","destination":"CASA DE CAMPO","busId":"4234","busTimeLeft":920,"busDistance":2745,"longitude":-3.73103140059,"latitude":40.41264537381,"busPositionType":1},{"stopId":608,"lineId":"138","isHead":"False","destination":"ALUCHE","busId":"4181","busTimeLeft":999999,"busDistance":3191,"longitude":-3.7266414712365,"latitude":40.411397511188,"busPositionType":1},{"stopId":608,"lineId":"33","isHead":"False","destination":"CASA DE CAMPO","busId":"4232","busTimeLeft":999999,"busDistance":7818,"longitude":-3.7622555004248,"latitude":40.404643143841,"busPositionType":1}]}
En la documentación de la API se pueden ver el resultado
stopId |
Stop Id |
int |
lineId |
Line Id |
string |
isHead |
true|false Stop is header for this line |
string |
destination |
Destination text |
string |
busId |
Bus id |
string |
busTimeLeft |
Time to arrive in seconds (if all 9, means more than 20 minutes) (if 0 bus in the stop) |
int |
busDistance |
Distance in meters |
int |
latitude |
Latitude in decimal degrees |
double |
longitude |
Longitude in decimal degrees |
double |
busPositionType |
Real or estimate |
int |
Los únicos campos que vamos a usar nosotros son:
- StopID
- lineID
- busTimeLeft. Todo 9 maś de 20 minutos. 0 -> Autobús en parada.
Esta llamada, devuelve, para cada parada, el tiempo de los dos autobuses más cercanos.