マップデータにリアルタイムでアクセスする
地図セグメントのデータにアクセスして取得するには、SegmentDataLoaderを使用できます。制限速度や道路属性など、OCMマップで使用可能なマップデータにアクセスするためのインターフェースを提供します。
注これはこの機能のベータリリースであるため、いくつかのバグや予期しない動作が発生する可能性があります。関連するAPIは、廃止のプロセスを経ずに、新しいリリースに変更される可能性があります。
SegmentDataLoaderはまず、データがインストールされているか、プリフェッチされているか、キャッシュされているかを確認し、使用できない場合は、要求されたタイルのオンラインでのダウンロードを試行します。- 操作は同期しており、呼び出し元のスレッドをブロックします。メインスレッドから呼び出された場合はメインスレッドをブロックします。最適なパフォーマンスを得るには、バックグラウンドスレッドからこれらのメソッドを呼び出すか、作業領域周辺のマップデータをプリフェッチすることが推奨されています。
getSegmentsAroundCoordinates()を呼び出すことにより、指定した位置に近いセグメントを表すOCMSegmentIdオブジェクトのリストを取得できます。取得すると、これらのIDは、道路のPhysicalAttributesやSegmentSpeedLimitなどの構造的属性および規制上の属性を含む詳細なセグメントデータを読み込むために使用できます。
位置情報に基づくセグメントクエリを使用する場合に最適な結果を得るには、未加工のGPS座標ではなく、マップマッチングした座標の使用を検討してください。MapMatcherは位置情報信号を道路ネットワークに合わせることができるため、正しい道路位置情報のセグメントデータを取得できます。MapMatcherはすでに一定のセグメント情報を提供していますが、完全なセグメントデータが必要な場合は、SegmentDataLoaderを使用してマップマッチングした座標を使用できます。セグメントデータをクエリする前に位置情報の精度を向上させる方法の詳細については、「マップマッチングの場所」を参照してください。
public void loadAndProcessSegmentData() {
List<OCMSegmentId> segmentIds;
SegmentData segmentData;
// The necessary SegmentDataLoaderOptions need to be turned on in order to find the requested information.
// It is recommended to turn on only the data you are interested in by setting the corresponding fields to true.
SegmentDataLoaderOptions segmentDataLoaderOptions = new SegmentDataLoaderOptions();
segmentDataLoaderOptions.loadBaseSpeeds = true;
segmentDataLoaderOptions.loadRoadAttributes = true;
double radiusInMeters = 500;
try {
segmentIds = segmentDataLoader.getSegmentsAroundCoordinates(startGeoCoordinates, radiusInMeters);
for (OCMSegmentId segmentId : segmentIds) {
segmentData = segmentDataLoader.loadData(segmentId, segmentDataLoaderOptions);
List<SegmentSpanData> segmentSpanDataList = segmentData.getSpans();
if (segmentSpanDataList == null) {
Log.e(TAG, "SegmentSpanDataList is null");
continue;
}
for (SegmentSpanData span : segmentSpanDataList) {
Log.d(TAG, "Physical attributes of " + span.toString() + " span.");
Log.d(TAG, "Private roads: " + span.getPhysicalAttributes().isPrivate);
Log.d(TAG, "Dirt roads: " + span.getPhysicalAttributes().isDirtRoad);
Log.d(TAG, "Bridge: " + span.getPhysicalAttributes().isBridge);
Log.d(TAG, "Tollway: " + span.getRoadUsages().isTollway);
Log.d(TAG, "Average expected speed: " + span.getPositiveDirectionBaseSpeedInMetersPerSecond());
}
}
} catch (MapDataLoaderException e) {
throw new RuntimeException(e);
}
}
fun loadAndProcessSegmentData() {
val segmentIds: MutableList<OCMSegmentId>
var segmentData: SegmentData
// The necessary SegmentDataLoaderOptions need to be turned on in order to find the requested information.
// It is recommended to turn on only the data you are interested in by setting the corresponding fields to true.
val segmentDataLoaderOptions = SegmentDataLoaderOptions()
segmentDataLoaderOptions.loadBaseSpeeds = true
segmentDataLoaderOptions.loadRoadAttributes = true
val radiusInMeters = 500.0
if (startGeoCoordinates == null) {
Toast.makeText(context, "You need to add a route beforehand as we use the start coordinates to search for segment data.", Toast.LENGTH_LONG).show()
return
}
Toast.makeText(context, "The app will now load attributes of a map segment. For more details check the logs.", Toast.LENGTH_LONG).show()
val startGeoCoordinatesNonNull = startGeoCoordinates ?: return logError("StartGeoCoordinates is null. Cannot load segment data.")
segmentIds = segmentDataLoader.getSegmentsAroundCoordinates(startGeoCoordinatesNonNull, radiusInMeters)
for (segmentId in segmentIds) {
segmentData = segmentDataLoader.loadData(segmentId, segmentDataLoaderOptions)
val segmentSpanDataList = segmentData.spans
for (span in segmentSpanDataList) {
Log.d(TAG, "Physical attributes of $span span.")
Log.d(TAG, "Private roads: ${span.physicalAttributes?.isPrivate}")
Log.d(TAG, "Dirt roads: ${span.physicalAttributes?.isDirtRoad}")
Log.d(TAG, "Bridge: ${span.physicalAttributes?.isBridge}")
Log.d(TAG, "Tollway: ${span.roadUsages?.isTollway}")
Log.d(TAG, "Average expected speed: ${span.positiveDirectionBaseSpeedInMetersPerSecond}")
}
}
}
この実装例は、GitHubの「RoutingWithAvoidanceOptions」サンプルアプリで確認できます。
26 日前の更新










