HERE iOS SDK Developer's Guide

Transit Station Search

Figure 1. Station Search by Coordinates

The Transit Stations Search feature allows users to discover transit stations by searching for stations around a specified location. For example, your application can look for the nearest subway station by retrieving all subway stations at the current location with the specified radius.

The follow code demonstrates how to trigger a station search by location:

// request manager singleton
NMAUrbanMobilityRequestManager *requestManager =
  [NMAUrbanMobilityRequestManager sharedRequestManager];

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

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

NMAUrbanMobilityStationSearchRequest *request =
  [requestManager createStationSearchRequestWithLocation:location];

// 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:completeSearch];
Figure 2. Station Search by Name

You can also search for public transit stations by providing its name. For example, a user searching for "Alexanderplatz" retrieves all stations that match that name. This search is location-aware, so results are sorted by proximity to the current location.

The following code demonstrates how to perform a station search and filter by the specified name:

// ...
// Search was triggered successfully
request.searchRange = 1000;
request.stationName = @"Alexanderplatz";

// 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:completeSearch];

You can also retrieve a station directly by specifying the stationIds while creating the NMAUrbanMobilityStationSearchRequest, as demonstrated in the following:

// List of station ids to search for
NSArray *stationIds = @[@"703280098"];

//create search request
NMAUrbanMobilityStationSearchRequest *request =
  [requestManager createStationSearchRequestWithIds:stationIds];

// 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:completeSearch];