I working on a project which requires me to calculate the total travel time, distance and fares incurred when travelling on Singapore’s public transport from many origins to one destination.
I was exploring the Onemap APIs and chanced upon the routing service API which I think can potentially help me get the data I need.
I am working with R to extract the data from the API. Currently, my plan is to experiment if I can get travel time, distance and fare for one point to my destination. If successful, I aim to generate multiple origins and use a loop to get the information I need. Here is an example of my code:
route_url <- "https://developers.onemap.sg/privateapi/routingsvc/route?"
orchard_rd <- (“1.3039805,103.8320321”)
beauty_word_mrt <- (“1.3416977,103.7759785”)
route_pt <- GET(paste0(route_url, “start=”, orchard_rd, “&end=”, beauty_word_mrt,
“&routeType=pt”, “&token=”, token ,
However, I have some questions about the structure of the response and how to extract the data I need:
When I change the parameter “numItineraries=x”, I still get a long list of itineraries (6 to be exact) even if I put x = 1. Is there a way for me to select the most efficient route (in terms of costs and time)?
Also, is the list of itineraries for the response already ordered i.e. itineraries[] is a more efficient route than itineraries[]?
Lastly, I’m wondering if there is a way for me to extract the total distance and time for each route?
I’m not too sure how to interpret response structure but (correct me if I’m wrong) I think the response gives the distances and timing of different segments along each route… Is there any way to piece everything together to give a summary of the total distance and total time?
Would appreciate if anyone would be able to help!