トランジットルーティング
トランジットルートは、 NMACoreRouter
を使用して NMATransportMode
計算されたルートで、 NMARoutingMode
IN NMATransportModePublicTransport
に設定されています。 トランジットルーティング機能を使用すると、既知のオンラインタイムテーブル情報を使用してトランジットルートを計算できます。
transitRoutingOptions
プロパティを使用すると、ボートを避けるなど、さまざまな制限を追加できます。 maximumChanges
プロパティを使用して、目的の輸送車両の変更数を制限することもできます。
NMACoreRouter
計算結果のブロックと calculateRouteWithStops:routingMode:completionBlock:
メソッド経由のルート結果を返します。 NMARoute
には、 NMAManeuver
クラスによって表された 1 つ以上の操作が含まれています。 これらの操作は、徒歩または公共交通機関による操作です。 公共の交通機関を利用する場合は、 NMAManeuver
NMATransitManeuver
にダウンキャストすることで、輸送に固有の情報にアクセスできます。 に NMATransitManeuver
は、 1 つ以上の NMATransitRouteElement
オブジェクトが含まれています。 NMATransitRouteElement
各荷物には、出発ステーション、到着ステーション、そのトランジット操作の移動時間が含まれています。 を使用したトランジットルートの例を次に示し NMACoreRouter
ます。
NMACoreRouter* coreRouter = [[NMACoreRouter alloc] init];
NMAGeoCoordinates* geoCoord1 =
[[NMAGeoCoordinates alloc] initWithLatitude:49.1966286 longitude:-123.0053635];
NMAGeoCoordinates* geoCoord2 =
[[NMAGeoCoordinates alloc] initWithLatitude:49.1947289 longitude:-123.1762924];
NMAWaypoint* waypoint1 = [[NMAWaypoint alloc] initWithGeoCoordinates:geoCoord1];
NMAWaypoint* waypoint2 = [[NMAWaypoint alloc] initWithGeoCoordinates:geoCoord2];
NSMutableArray* stops = [[NSMutableArray alloc] initWithCapacity:4];
[stops addObject:waypoint1];
[stops addObject:waypoint2];
NMARoutingMode* routingMode = [[NMARoutingMode alloc]
initWithRoutingType:NMARoutingTypeFastest
transportMode:NMATransportModePublicTransport
routingOptions:0];
[coreRouter calculateRouteWithStops:stops routingMode:routingMode
completionBlock:^(NMARouteResult *routeResult, NMARoutingError error) {
// If the route was calculated successfully
if (!error && routeResult && routeResult.routes.count > 0)
{
NMARoute* route = [routeResult.routes objectAtIndex:0];
// Render the route on the map
NMAMapRoute* mapRoute = [NMAMapRoute mapRouteWithRoute:route];
[mapView addMapObject:mapRoute];
// In order to see the entire route, we orientate the map view
// accordingly
[mapView setBoundingBox:route.boundingBox
withAnimation:NMAMapAnimationLinear];
}
else if (error)
{
// Display a message indicating route calculation failure
}
}];
トランジットルートを表示する前 NMAMapRoute
に、がトランジットラインの色を表示するように、トランジットを含めるようにマップ スキームを設定します。 setBoundingBox:withAnimation:
また、メソッドを使用して、ビューをパンおよびズームし、ルート全体を表示することもできます。
// sets the map scheme to include transit
[mapView setMapScheme:NMAMapSchemeNormalDayTransit];
// zoom to display the entire route
[mapView setBoundingBox:route.boundingBox withAnimation:NMAMapAnimationBow];