HERE iOS SDK Developer's Guide

Next Nearby Departures

You can use the HERE SDK to query for the next transit departures for a particular station. Next nearby departure information is based on the timetable information provided by transit agencies, and it includes all types and times of departures from one station at a given time.

Figure 1. Station Departures

To query for the departures, create a request by using the station ID and location parameters and add a completion block, or simply an NMAUrbanMobilityStation object. The returned completion block contains a list of NMAUrbanMobilityDeparture objects that is sorted by the departure times.

// Departures manager singleton
NMAUrbanMobilityRequestManager *departuresManager =
  [NMAUrbanMobilityRequestManager sharedRequestManager];

// Chicago, Millenium Park
NMAGeoCoordinates *loc =
  [NMAGeoCoordinates geoCoordinatesWithLatitude:41.882736 longitude:-87.622004];

// Search completion block
void (^completeQuery) (NSArray *, NSError *) =
  ^(NSArray *departures, NSError *error) {
  if (error) {
    // Handle error
    switch (error.code) {
      case NMAUrbanMobilityErrorNotFound:
        // No departures were found
        break;
      default:
        // Handle other errors
        break;
    }
  } else {
    for (NMAUrbanMobilityDeparture *departure in departures) {
      // Handle departure
    }
  }
};

NMAUrbanMobilityDepartureBoardRequest *request =
  [departuresManager createDepartureBoardRequestWithStationId:@"703280098" location:loc];

// IMPORTANT:Ensure the request object is retained (for example, make it a property)
// until the request completes

// Start an asynchronous departures query
// If success is NO the request was not started and the completion handler will not be called
BOOL success = [request startWithCompletionBlock:completeQuery];

All Next Departures

To query for departure information of stations in a given area, create a request by using the location parameter and add a completion block. The returned completion block contains a list of NMAUrbanMobilityStationWithDepartureBoard and NMAUrbanMobilityLine objects that contain departure information, which are sorted by the departure times. NMAUrbanMobilityStationWithDepartureBoard is a child implementation of the NMAUrbanMobilityStation class.

// Departures manager singleton
NMAUrbanMobilityRequestManager *departuresManager =
  [NMAUrbanMobilityRequestManager sharedRequestManager];

// Chicago, Millenium Park
NMAGeoCoordinates *loc =
  [NMAGeoCoordinates geoCoordinatesWithLatitude:41.882736 longitude:-87.622004];

// Search completion block
void (^completeQuery) (NSArray *, NSArray *, NSError *) =
  ^(NSArray *stations, NSArray *transports, NSError *error) {
  if (error) {
    // Handle error
    switch (error.code) {
      case NMAUrbanMobilityErrorNotFound:
        // No departures were found
        break;
      default:
        // Handle other errors
        break;
    }
  } else {
    for (NMAUrbanMobilityStationWithDepartureBoard *station in stations) {
      NMAUrbanMobilityDepartureBoard *departureBoard = station.departureBoard;
      for (NMAUrbanMobilityDeparture *departure in departureBoard.departures) {
        // Handle departure
      }
    }
  }
};

NMAUrbanMobilityMultiBoardRequest *request =
  [departuresManager createMultiBoardRequestWithLocation:loc];

// You can set other search parameters here before starting the search

// IMPORTANT:Ensure the request object is retained (for example, make it a property)
// until the request completes

// Start an asynchronous departures query
// If success is NO the request was not started and the completion handler will not be called
BOOL success = [request startWithCompletionBlock:completeQuery];

You can also set the radius and the stationIds properties in the NMAUrbanMobilitySearchRequest object to limit the search.