इस सेक्शन में, Android for Cars App लाइब्रेरी के साथ Navigation SDK का इस्तेमाल करने का तरीका बताया गया है. इसकी मदद से, डैशबोर्ड में मौजूद head units पर, अपने ऐप्लिकेशन का नेविगेशन अनुभव दिखाया जा सकता है. अगर किसी उपयोगकर्ता के डैशबोर्ड में मौजूद सिस्टम पर Android Auto की सुविधा काम करती है, तो उपयोगकर्ता अपने फ़ोन को यूनिट से कनेक्ट करके, कार के डिसप्ले पर सीधे आपका ऐप्लिकेशन इस्तेमाल कर सकते हैं. बोलकर निर्देश देने की सुविधा, कार के स्पीकर पर भी काम करती है.
Android for Cars App Library Android ऐप्लिकेशन को Android Auto पर चलाने की सुविधा देती है. इसके लिए, यह ड्राइवर की सुरक्षा के लिए मंज़ूरी पा चुके विज़ुअल टेंप्लेट का सेट उपलब्ध कराती है. ये टेंप्लेट, डैशबोर्ड में मौजूद यूज़र इंटरफ़ेस (यूआई) के कंट्रोल को फ़ोन के कंट्रोल से अलग रखते हैं. ऐसा, ड्राइवर का ध्यान भटकने से रोकने के लिए किया जाता है.
जब Navigation SDK की मदद से बनाए गए ऐप्लिकेशन को Android Auto के साथ काम करने की अनुमति दी जाती है, तो नेविगेशन के अनुभव के लिए एक अतिरिक्त व्यू उपलब्ध कराया जाता है.
इससे, मैप के दो व्यू मिलते हैं—एक फ़ोन के लिए और एक हेड यूनिट के लिए. दोनों डिसप्ले को Navigator.java से निर्देश मिलते हैं. यह एक सिंगलटन है.
डैशबोर्ड में मौजूद सिस्टम, सुरक्षा के लिए मंज़ूरी पा चुके इंटरैक्टिव एलिमेंट दिखाता है, ताकि उपयोगकर्ता बिना किसी परेशानी के अपनी मंज़िल तक सुरक्षित तरीके से नेविगेट कर सके. उपयोगकर्ता, आपके ऐप्लिकेशन की खास सुविधाओं के साथ भी इंटरैक्ट कर सकता है. जैसे, ऑर्डर स्वीकार या अस्वीकार करना या मैप पर ग्राहक की जगह देखना. डैशबोर्ड में मौजूद यूनिट पर, ऑर्डर के स्टेटस से जुड़े अपडेट भी दिख सकते हैं.
कनेक्ट किया गया फ़ोन, Navigation SDK के स्टैंडर्ड अनुभव या आपके ऐप्लिकेशन में मौजूद किसी अन्य व्यू या वर्कफ़्लो को दिखाता रह सकता है. इस सुविधा की मदद से, कस्टम फ़ंक्शनैलिटी उपलब्ध कराई जा सकती है. हो सकता है कि यह कार की स्क्रीन पर ठीक से काम न करे.
सेट अप करें
अपने ऐप्लिकेशन को Android Auto के साथ काम करने के लिए सेट अप करने के पहले चरण में, Android Auto के साथ कार की सेवा सेट अप करना शामिल है. इसके बाद, अपने Navigation SDK ऐप्लिकेशन में TurnByTurn लाइब्रेरी चालू करना शामिल है.
Android Auto का इस्तेमाल शुरू करना
Android Auto के साथ काम करने के लिए डिज़ाइन की गई, Navigation SDK की सुविधाओं का इस्तेमाल शुरू करने से पहले, आपको अपने ऐप्लिकेशन के लिए कार की सेवा सेट अप करनी होगी, ताकि Android Auto उसे खोज सके.
यह तरीका अपनाएं. इसके सभी चरण, Android for Cars डेवलपर दस्तावेज़ में देखे जा सकते हैं:
- Android Auto की बुनियादी सुविधाओं के बारे में जानें.
- Android for Cars App लाइब्रेरी इंस्टॉल करें.
- Android Auto को शामिल करने के लिए, अपने ऐप्लिकेशन की मेनिफ़ेस्ट फ़ाइल कॉन्फ़िगर करें.
- अपने मेनिफ़ेस्ट में, कार-ऐप्लिकेशन का कम से कम लेवल 1 तय करें.
- बनाएं
आपका
CarAppServiceऔर सेशन.
Navigation SDK सेट अप करना
कार के लिए ऐप्लिकेशन की सेवा सेट अप करने के बाद, Navigation SDK का इस्तेमाल किया जा सकता है.
- अगर आपने अपने ऐप्लिकेशन में Navigation SDK को पहले से इंटिग्रेट नहीं किया है, तो अपना प्रोजेक्ट सेट अप करें.
- अपने ऐप्लिकेशन के लिए, TurnbyTurn के दिशा-निर्देशों का फ़ीड चालू करें.
- ज़रूरी नहीं. जनरेट किए गए आइकॉन इस्तेमाल करें Navigation SDK से.
- मैप बनाएं
क्लास का इस्तेमाल करके, Android Auto Surface पर दिया गया है
क्लास में.
NavigationViewForAutoScreen - TurnbyTurn लाइब्रेरी के डेटा से, Android Auto के नेविगेशन टेंप्लेट में जानकारी भरें.
अब आपके पास अपने ऐप्लिकेशन को नेविगेशन की जानकारी देने के लिए, रजिस्टर की गई सेवा है. साथ ही, आपका ऐप्लिकेशन Android Auto से कनेक्ट हो सकता है. अब नेविगेशन के बाकी एलिमेंट बनाए जा सकते हैं. इनकी मदद से, आपका ऐप्लिकेशन Android Auto के साथ ठीक से काम कर पाएगा:
- मैप और नेविगेशन यूज़र इंटरफ़ेस (यूआई) बनाना
- मैप इंटरैक्शन की सुविधा चालू करना
- नेविगेशन के निर्देश दिखाना
- यह पक्का करना कि सही तरह के मैन्यूवर इस्तेमाल किए जाएं
मैप और नेविगेशन यूज़र इंटरफ़ेस (यूआई) बनाना
NavigationViewForAuto क्लास, Android Auto की स्क्रीन पर मैप और नेविगेशन यूज़र इंटरफ़ेस (यूआई) रेंडर करती है. यह फ़ोन के लिए NavigationView जैसी ही कई सुविधाएं देती है. हालांकि, इसमें इंटरैक्टिविटी सीमित होती है. Android Auto से मिले
Surface
पर बनाने के लिए, NavigationViewForAuto का इस्तेमाल करें:
private boolean isSurfaceReady(SurfaceContainer surfaceContainer) {
return surfaceContainer.getSurface() != null
&& surfaceContainer.getDpi() != 0
&& surfaceContainer.getHeight() != 0
&& surfaceContainer.getWidth() != 0;
}
@Override
public void onSurfaceAvailable(@NonNull SurfaceContainer surfaceContainer) {
if (!isSurfaceReady(surfaceContainer)) {
return;
}
virtualDisplay =
getCarContext()
.getSystemService(DisplayManager.class)
.createVirtualDisplay(
VIRTUAL_DISPLAY_NAME,
surfaceContainer.getWidth(),
surfaceContainer.getHeight(),
surfaceContainer.getDpi(),
surfaceContainer.getSurface(),
DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY);
presentation = new Presentation(getCarContext(), virtualDisplay.getDisplay());
navigationView = new NavigationViewForAuto(getCarContext());
navigationView.onCreate(null);
navigationView.onStart();
navigationView.onResume();
presentation.setContentView(navigationView);
presentation.show();
navigationView.getMapAsync(googleMap -> this.googleMap = googleMap);
}
@Override
public void onSurfaceDestroyed(@NonNull SurfaceContainer surfaceContainer) {
navigationView.onPause();
navigationView.onStop();
navigationView.onDestroy();
presentation.dismiss();
virtualDisplay.release();
}
मैप इंटरैक्शन की सुविधा चालू करना
ड्राइवर की सुरक्षा के लिए, Android Auto स्क्रीन Surface इंटरैक्शन को
SurfaceCallback
के कुछ तरीकों तक सीमित रखता है. डैशबोर्ड में मौजूद स्क्रीन पर, मैप के साथ ड्राइवर के सीमित इंटरैक्शन के लिए, इन कॉलबैक का इस्तेमाल करें. उदाहरण के लिए, onClick और onScale, उपयोगकर्ता के टैप और पिंच जेस्चर से जुड़े होते हैं. इंटरैक्टिविटी कॉलबैक को, मैप
ऐक्शन
स्ट्रिप
का इस्तेमाल इस तरह करना चाहिए:
मैप इंटरैक्टिविटी कॉलबैक पाने के लिए, आपके ऐप्लिकेशन को Action.PAN बटन का इस्तेमाल करना होगा.
उपयोगकर्ता की अन्य कार्रवाइयों के लिए, मैप ऐक्शन स्ट्रिप में बटन जोड़ें.
Surface कॉलबैक चालू करना
@NonNull
@Override
public Template onGetTemplate() {
return new NavigationTemplate.Builder()
.setActionStrip(new ActionStrip.Builder().build())
.setMapActionStrip(new ActionStrip.Builder().addAction(Action.PAN).build())
.build();
}
पिंच करके ज़ूम करना
@Override
public void onScale(float focusX, float focusY, float scaleFactor) {
CameraUpdate update =
CameraUpdateFactory.zoomBy((scaleFactor - 1),
new Point((int) focusX, (int) focusY));
googleMap.animateCamera(update); // map is set in onSurfaceAvailable.
}
पैन करना
@Override
public void onScroll(float distanceX, float distanceY) {
googleMap.moveCamera(CameraUpdateFactory.scrollBy(distanceX, distanceY));
}
नेविगेशन के निर्देश दिखाना
इस सेक्शन में, नेविगेशन पोस्ट के लिए ऑब्ज़र्वर सेट अप करने और टर्न कार्ड टेंप्लेट में नेविगेशन के निर्देश भरने का तरीका बताया गया है.
Android Auto का नेविगेशन टेंप्लेट टर्न कार्ड उपलब्ध कराता है. इसमें, मौजूदा यात्रा से जुड़ी नेविगेशन की जानकारी दिखती है. Navigation SDK में मौजूद TurnByTurn लाइब्रेरी, नेविगेशन की यह जानकारी उपलब्ध कराती है. आपका कोड, Android Auto के नेविगेशन टेंप्लेट में जानकारी भरने के लिए इसका इस्तेमाल करता है.
ऑब्ज़र्वर सेट अप करना
यहां दिए गए उदाहरण में, SampleApplication एक कस्टम ऐप्लिकेशन क्लास है. यह
MutableLiveData<NavInfo> ऑब्जेक्ट को बनाए रखती है. जब ऑब्ज़र्वर को नेविगेटर ऑब्जेक्ट से कोई
अपडेट मिलता है, तो वह इस NavInfo ऑब्जेक्ट को
NavInfoMutableLiveData पर पोस्ट करता है, जिसे SampleApplication क्लास से बनाए रखा गया है.
यहां दिए गए उदाहरण में, Android Auto स्क्रीन के अपने लागू करने के तरीके में, इस ऑब्जेक्ट के लिए एक ऑब्ज़र्वर रजिस्टर किया गया है.
public SampleAndroidAutoNavigationScreen(@NonNull CarContext carContext,
SampleApplication application) {
super(carContext);
getCarContext().getCarService(AppManager.class).setSurfaceCallback(this);
application.getNavInfoMutableLiveData().observe(this, this::processNextStep);
}
नेविगेशन की जानकारी भरना
यहां दिए गए कोड स्निपेट में, Android Auto के टेंप्लेट में मौजूदा रूटिंग की जानकारी भरने का तरीका दिखाया गया है. इसमें, रास्ते, दूरी, और आइकॉन शामिल हैं. इन डिसप्ले एलिमेंट के बारे में ज़्यादा जानने के लिए, फ़ीड डिसप्ले में जानकारी भरना लेख पढ़ें.
कोड का उदाहरण देखने के लिए, बड़ा करें.
private RoutingInfo currentRoutingInfo; @NonNull @Override public Template onGetTemplate() { NavigationTemplate.Builder navigationTemplateBuilder = new NavigationTemplate.Builder() .setActionStrip(...) .setMapActionStrip(...) if (currentRoutingInfo != null) { navigationTemplateBuilder.setNavigationInfo(currentRoutingInfo); } return navigationTemplateBuilder.build(); } private void processNextStep(NavInfo navInfo) { if (navInfo == null || navinfo.getCurrentStep() == null) { return; } /** * Converts data received from the Navigation data feed * into Android-Auto compatible data structures. For more information * see the "Ensure correct maneuver types" below. */ Step currentStep = buildStepFromStepInfo(navInfo.getCurrentStep()); Distance distanceToStep = buildDistanceFromMeters(navInfo.getDistanceToCurrentStepMeters()); currentRoutingInfo = new RoutingInfo.Builder().setCurrentStep(currentStep, distanceToStep).build(); // Invalidate the current template which leads to another onGetTemplate call. invalidate(); } private Step buildStepFromStepInfo(StepInfo stepInfo) { IconCompat maneuverIcon = IconCompat.createWithBitmap(stepInfo.getManeuverBitmap()); Maneuver.Builder maneuverBuilder = newManeuver.Builder( ManeuverConverter .getAndroidAutoManeuverType(stepInfo.getManeuver())); CarIcon maneuverCarIcon = new CarIcon.Builder(maneuverIcon).build(); maneuverBuilder.setIcon(maneuverCarIcon); Step.Builder stepBuilder = new Step.Builder() .setRoad(stepInfo.getFullRoadName()) .setCue(stepInfo.getFullInstructionText()) .setManeuver(maneuverBuilder.build()); if (stepInfo.getLanes() != null && stepInfo.getLanesBitmap() != null) { for (Lane lane : buildAndroidAutoLanesFromStep(stepInfo)) { stepBuilder.addLane(lane); } IconCompat lanesIcon = IconCompat.createWithBitmap(stepInfo.getLanesBitmap()); CarIcon lanesImage = new CarIcon.Builder(lanesIcon).build(); stepBuilder.setLanesImage(lanesImage); } return stepBuilder.build(); } /* * Constructs a {@code Distance} object in imperial measurement units. * In a real world scenario, units would be based on locale. */ private Distance buildDistanceFromMeters(int distanceMeters) { // Distance can be negative so set the min distance to 0. int remainingFeet = (int) max(0, distanceMeters * DistanceConstants.FEET_PER_METER); double remainingMiles = ((double) remainingFeet) / DistanceConstants.FEET_PER_MILE; // Only use the tenths place digit if distance is less than 10 miles and show // feet if distance is less than 0.25 miles. if (remainingMiles >= DistanceConstants.MIN_MILES_TO_SHOW_INTEGER) { return Distance.create((int) round(remainingMiles), Distance.UNIT_MILES); } else if (remainingMiles >= 0.25) { return Distance.create((int) remainingMiles, Distance.UNIT_MILES); } else { return Distance.create(remainingFeet, Distance.UNIT_FEET); } }
यह पक्का करना कि सही तरह के मैन्यूवर इस्तेमाल किए जाएं
Android Auto की कार लाइब्रेरी में इस्तेमाल किए जाने वाले मैन्यूवर, TurnByTurn लाइब्रेरी से मिले मैन्यूवर के मुताबिक होते हैं. हालांकि, आपको Navigation SDK के मैन्यूवर को, Android Auto की कार लाइब्रेरी में मान्य एलान में बदलना होगा. यहां दी गई टेबल में, कुछ फ़ील्ड के लिए कॉरस्पॉन्डेंस दिखाया गया है. इसके बाद, आपकी सुविधा के लिए, कनवर्टर यूटिलिटी का सैंपल दिया गया है.
| Turn-by-Turn लाइब्रेरी का मैन्यूवर | Android Auto का मैन्यूवर |
|---|---|
DEPART |
TYPE_DEPART |
DESTINATION |
TYPE_DESTINATION |
DESTINATION_LEFT |
TYPE_DESTINATION_LEFT |
DESTINATION_RIGHT |
TYPE_DESTINATION_RIGHT |
TURN_U_TURN_CLOCKWISE |
TYPE_U_TURN_RIGHT |
ON_RAMP_LEFT |
TYPE_ON_RAMP_NORMAL_LEFT |
ON_RAMP_RIGHT |
TYPE_ON_RAMP_NORMAL_RIGHT |
ON_RAMP_SLIGHT_LEFT |
TYPE_ON_RAMP_SLIGHT_LEFT |
FORK_RIGHT |
TYPE_FORK_RIGHT |
कोड का उदाहरण देखने के लिए, बड़ा करें.
import com.google.android.libraries.mapsplatform.turnbyturn.model.Maneuver; import com.google.common.collect.ImmutableMap; import javax.annotation.Nullable; /** Converter that converts between turn-by-turn and Android Auto Maneuvers. */ public final class ManeuverConverter { private ManeuverConverter() {} // Map from turn-by-turn Maneuver to Android Auto Maneuver.Type. private static final ImmutableMap<Integer, Integer> MANEUVER_TO_ANDROID_AUTO_MANEUVER_TYPE = ImmutableMap.<Integer, Integer>builder() .put(Maneuver.DEPART, androidx.car.app.navigation.model.Maneuver.TYPE_DEPART) .put(Maneuver.DESTINATION, androidx.car.app.navigation.model.Maneuver.TYPE_DESTINATION) .put( Maneuver.DESTINATION_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_DESTINATION_LEFT) .put( Maneuver.DESTINATION_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_DESTINATION_RIGHT) .put(Maneuver.STRAIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_STRAIGHT) .put(Maneuver.TURN_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_TURN_NORMAL_LEFT) .put( Maneuver.TURN_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_TURN_NORMAL_RIGHT) .put(Maneuver.TURN_KEEP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_KEEP_LEFT) .put(Maneuver.TURN_KEEP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_KEEP_RIGHT) .put( Maneuver.TURN_SLIGHT_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_TURN_SLIGHT_LEFT) .put( Maneuver.TURN_SLIGHT_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_TURN_SLIGHT_RIGHT) .put( Maneuver.TURN_SHARP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_TURN_SHARP_LEFT) .put( Maneuver.TURN_SHARP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SHARP_RIGHT) .put( Maneuver.TURN_U_TURN_CLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_U_TURN_RIGHT) .put( Maneuver.TURN_U_TURN_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_U_TURN_LEFT) .put( Maneuver.MERGE_UNSPECIFIED, androidx.car.app.navigation.model.Maneuver.TYPE_MERGE_SIDE_UNSPECIFIED) .put(Maneuver.MERGE_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_MERGE_LEFT) .put(Maneuver.MERGE_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_MERGE_RIGHT) .put(Maneuver.FORK_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_FORK_LEFT) .put(Maneuver.FORK_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_FORK_RIGHT) .put( Maneuver.ON_RAMP_UNSPECIFIED, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_RIGHT) .put( Maneuver.ON_RAMP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_LEFT) .put( Maneuver.ON_RAMP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_RIGHT) .put( Maneuver.ON_RAMP_KEEP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_LEFT) .put( Maneuver.ON_RAMP_KEEP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_NORMAL_RIGHT) .put( Maneuver.ON_RAMP_SLIGHT_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SLIGHT_LEFT) .put( Maneuver.ON_RAMP_SLIGHT_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SLIGHT_RIGHT) .put( Maneuver.ON_RAMP_SHARP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SHARP_LEFT) .put( Maneuver.ON_RAMP_SHARP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_SHARP_RIGHT) .put( Maneuver.ON_RAMP_U_TURN_CLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_U_TURN_RIGHT) .put( Maneuver.ON_RAMP_U_TURN_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ON_RAMP_U_TURN_LEFT) .put( Maneuver.OFF_RAMP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_LEFT) .put( Maneuver.OFF_RAMP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_RIGHT) .put( Maneuver.OFF_RAMP_KEEP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_LEFT) .put( Maneuver.OFF_RAMP_KEEP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_RIGHT) .put( Maneuver.OFF_RAMP_SLIGHT_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_LEFT) .put( Maneuver.OFF_RAMP_SLIGHT_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_SLIGHT_RIGHT) .put( Maneuver.OFF_RAMP_SHARP_LEFT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_LEFT) .put( Maneuver.OFF_RAMP_SHARP_RIGHT, androidx.car.app.navigation.model.Maneuver.TYPE_OFF_RAMP_NORMAL_RIGHT) .put( Maneuver.ROUNDABOUT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW) .put( Maneuver.ROUNDABOUT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW) .put( Maneuver.ROUNDABOUT_STRAIGHT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_CW) .put( Maneuver.ROUNDABOUT_STRAIGHT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_CCW) .put( Maneuver.ROUNDABOUT_LEFT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_LEFT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_RIGHT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_RIGHT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SLIGHT_LEFT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SLIGHT_LEFT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SLIGHT_RIGHT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SLIGHT_RIGHT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SHARP_LEFT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SHARP_LEFT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SHARP_RIGHT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_SHARP_RIGHT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_U_TURN_CLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_U_TURN_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver .TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) .put( Maneuver.ROUNDABOUT_EXIT_CLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_EXIT_CW) .put( Maneuver.ROUNDABOUT_EXIT_COUNTERCLOCKWISE, androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_EXIT_CCW) .put(Maneuver.FERRY_BOAT, androidx.car.app.navigation.model.Maneuver.TYPE_FERRY_BOAT) .put(Maneuver.FERRY_TRAIN, androidx.car.app.navigation.model.Maneuver.TYPE_FERRY_TRAIN) .put(Maneuver.NAME_CHANGE, androidx.car.app.navigation.model.Maneuver.TYPE_NAME_CHANGE) .buildOrThrow(); /** Represents the roundabout turn angle for a slight turn in either right or left directions. */ private static final int ROUNDABOUT_ANGLE_SLIGHT = 10; /** Represents the roundabout turn angle for a normal turn in either right or left directions. */ private static final int ROUNDABOUT_ANGLE_NORMAL = 45; /** Represents the roundabout turn angle for a sharp turn in either right or left directions. */ private static final int ROUNDABOUT_ANGLE_SHARP = 135; /** Represents the roundabout turn angle for a u-turn in either right or left directions. */ private static final int ROUNDABOUT_ANGLE_U_TURN = 180; /** * Returns the corresponding {@link androidx.car.app.navigation.model.Maneuver.Type} for the given * direction {@link Maneuver} * * @throws {@link IllegalArgumentException} if the given maneuver does not have a corresponding * Android Auto Maneuver type. */ public static int getAndroidAutoManeuverType(@Maneuver int maneuver) { if (MANEUVER_TO_ANDROID_AUTO_MANEUVER_TYPE.containsKey(maneuver)) { return MANEUVER_TO_ANDROID_AUTO_MANEUVER_TYPE.get(maneuver); } throw new IllegalArgumentException( String.format( "Given turn-by-turn Maneuver %d cannot be converted to an Android Auto equivalent.", maneuver)); } /** * Returns the corresponding Android Auto roundabout angle for the given turn {@link Maneuver}. * Returns {@code null} if given maneuver does not involve a roundabout with a turn. */ @Nullable public static Integer getAndroidAutoRoundaboutAngle(@Maneuver int maneuver) { if (maneuver == Maneuver.ROUNDABOUT_LEFT_CLOCKWISE || maneuver == Maneuver.ROUNDABOUT_RIGHT_CLOCKWISE || maneuver == Maneuver.ROUNDABOUT_LEFT_COUNTERCLOCKWISE || maneuver == Maneuver.ROUNDABOUT_RIGHT_COUNTERCLOCKWISE) { return ROUNDABOUT_ANGLE_NORMAL; } if (maneuver == Maneuver.ROUNDABOUT_SHARP_LEFT_CLOCKWISE || maneuver == Maneuver.ROUNDABOUT_SHARP_RIGHT_CLOCKWISE || maneuver == Maneuver.ROUNDABOUT_SHARP_LEFT_COUNTERCLOCKWISE || maneuver == Maneuver.ROUNDABOUT_SHARP_RIGHT_COUNTERCLOCKWISE) { return ROUNDABOUT_ANGLE_SHARP; } if (maneuver == Maneuver.ROUNDABOUT_SLIGHT_LEFT_CLOCKWISE || maneuver == Maneuver.ROUNDABOUT_SLIGHT_RIGHT_CLOCKWISE || maneuver == Maneuver.ROUNDABOUT_SLIGHT_LEFT_COUNTERCLOCKWISE || maneuver == Maneuver.ROUNDABOUT_SLIGHT_RIGHT_COUNTERCLOCKWISE) { return ROUNDABOUT_ANGLE_SLIGHT; } if (maneuver == Maneuver.ROUNDABOUT_U_TURN_CLOCKWISE || maneuver == Maneuver.ROUNDABOUT_U_TURN_COUNTERCLOCKWISE) { return ROUNDABOUT_ANGLE_U_TURN; } return null; } }
संबंधित दस्तावेज़
- Turn-by-turn के दिशा-निर्देशों का फ़ीड चालू करना: सबसे पहले, turn-by-turn की सुविधा इंटिग्रेट करें, ताकि आपका ऐप्लिकेशन Android Auto के साथ काम कर सके.
- फ़ीड डिसप्ले में जानकारी भरना: दिशा-निर्देशों की जानकारी के लिए, डेटा फ़ील्ड ऐक्सेस करें और आइकॉन इस्तेमाल करें.