HERE iOS SDK Developer's Guide

Coverage Search

Urban Mobility Coverage Search provides detailed information about the regions and cities with public transit data that are supported by HERE SDK. For example, you can get a list of cities that have transit data coverage by using a query request with a search area. You can create this type of request by using the createCityCoverageRequest method in NMAUrbanMobilityRequestManager to generate a city coverage request object.

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

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

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

NMAUrbanMobilityCityCoverageRequest *request =
  [requestManager createCityCoverageRequest];

// you can set additional request parameters here
request.location = location;
request.radius = 4000;
request.updateType = NMACoverageUpdateType.NMACoverageUpdateTypeUpdated;

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

Another supported type of coverage search uses a query string to look for cities with names that begin with this substring. You can create this type of request by using the createCitySearchRequestWithCity: method in NMAUrbanMobilityRequestManager.

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

// Search completion block
void (^completeSearch) (NMAUrbanMobilityCitySearchResult *, NSError *) =
  ^(NMAUrbanMobilityCitySearchResult *searchResult, NSError *error) {
  if (error) {
    // Handle error
    switch (error.code) {
      case NMAUrbanMobilityErrorNotFound:
        // No stations were found
        break;
      default:
        // Handle other errors
        break;
    }
  } else {
    NSArray *cities = searchResult.cities;
    for (NMAUrbanMobilityCity *city in cities) {
      // Handle city
      NSString *cityname = city.name;
      float coverageQuality = city.quality;
    }
  }
};

NSString *searchText = @"Rome";

NMAUrbanMobilityCityCoverageRequest *request =
  [requestManager createCitySearchRequestWithCity:searchText];

// 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 use NMAUrbanMobilityNearbyCoverageRequest to search for coverage information around a given location. This type of search returns information of the city that contains this location. If there is no transit stop within 2 kilometers of the location, the request returns the first five nearest transit stops outside of the 2 kilometers area. This type of search result is also known as an "Explored Coverage". The following code demonstrates how to retrieve both nearby and explored coverage results.

NMAGeoCoordinates *location =
  [NMAGeoCoordinates geoCoordinatesWithLatitude:52.521918 longitude:13.413215];

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

// Search completion block
void (^completeSearch) (NMAUrbanMobilityNearbyCoverageResult *, NSError *) =
  ^(NMAUrbanMobilityNearbyCoverageResult *coverageResult, NSError *error) {
  if (error) {
    // Handle error
    switch (error.code) {
      case NMAUrbanMobilityErrorNotFound:
        // No stations were found
        break;
      default:
        // Handle other errors
        break;
    }
  } else {
    NSInteger *radius = coverageResult.radius;
    NMAUrbanMobilityCity *city = coverageResult.city;
    NMAUrbanMobilityExploredCoverage *exploredCoverage = coverageResult.exploredCoverage;
    if (!exploredCoverage) {
      // exploredCoverage.stations
    }
  }
};

NMAUrbanMobilityNearbyCoverageRequest *request =
  [requestManager createNearbyCoverageRequestForLocation: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]