सभी डिवाइसों को देखना

इस सेक्शन में JavaScript फ़्लीट ट्रैकिंग लाइब्रेरी को इस्तेमाल करने का तरीका बताया गया है फ़्लीट देखने के लिए. इन प्रोसेस में यह माना जाता है कि आपने सभी डिवाइसों को सेट अप कर लिया है ट्रैकिंग लाइब्रेरी और मैप लोड किया गया. जानकारी के लिए, यह देखें JavaScript फ़्लीट ट्रैकिंग लाइब्रेरी सेट अप करें.

इस दस्तावेज़ में नीचे दी गई बातों के बारे में बताया गया है. फ़्लीट:

  1. फ़्लीट को ट्रैक करना शुरू करें.
  2. इवेंट सुनें और गड़बड़ियां ठीक करें.
  3. ट्रैकिंग बंद करें.
  4. फ़्लीट को देखते समय, एक वाहन को ट्रैक करना.

फ़्लीट को ट्रैक करना शुरू करें

सभी डिवाइसों को ट्रैक करने के लिए, आपको सभी डिवाइसों की जगह की जानकारी देने वाली कंपनी को इंस्टैंशिएट करना होगा और नीचे बताए गए के अनुसार मैप व्यूपोर्ट के लिए स्थान प्रतिबंध सेट करें सेक्शन.

फ़्लीट की जगह की जानकारी देने वाली कंपनी को इंस्टैंशिएट करें

JavaScript फ़्लीट ट्रैकिंग लाइब्रेरी में एक स्थान कंपनी शामिल है जो Fleet Engine से कई गाड़ियां फ़ेच करता है.

इसे इंस्टैंशिएट करने के लिए, यह तरीका अपनाएं:

  1. अपने प्रोजेक्ट आईडी का इस्तेमाल करें. साथ ही, टोकन फ़ेचर का रेफ़रंस इस्तेमाल करें.

  2. वाहन फ़िल्टर क्वेरी का इस्तेमाल करें वाहन फ़िल्टर क्वेरी से यह कंट्रोल होता है कि जिन वाहनों को मैप पर दिखाता है. फ़िल्टर, फ़्लीट इंजन को भेजा जाता है.

    • मांग पर उपलब्ध सेवाओं के लिए, vehicleFilter का इस्तेमाल करें. साथ ही, ListVehiclesRequest.filter की समीक्षा करें
    • शेड्यूल किए गए टास्क के लिए, deliveryVehicleFilter का इस्तेमाल करें और समीक्षा करें ListDeliveryVehiclesRequest.filter
  3. बाउंडिंग, वाहन के डिसप्ले के लिए सेट करें. इसके लिए locationRestriction का इस्तेमाल करें मैप पर वाहन दिखाने के लिए पूरा इलाका सीमित करें. जगह जब तक इसे सेट नहीं किया जाता है, तब तक कंपनी चालू नहीं होगी. जगह की सीमाएं इनमें से किसी एक पर सेट की जा सकती हैं कंस्ट्रक्टर में या कंस्ट्रक्टर के बाद में.

  4. मैप व्यू शुरू करना.

इन उदाहरणों में, फ़्लीट की जगह की जानकारी देने वाली कंपनी को इंस्टैंशिएट करने का तरीका बताया गया है ऑन-डिमांड और शेड्यूल किए गए, दोनों तरह के टास्क उपलब्ध होते हैं. यहां दिए गए उदाहरणों में बताया गया है कि जगह की जानकारी देने वाला बनाने के लिए, कंस्ट्रक्टर में locationRestriction सक्रिय है.

मांग पर यात्राएं

JavaScript

locationProvider =
    new google.maps.journeySharing
        .FleetEngineFleetLocationProvider({
          projectId,
          authTokenFetcher,

          // Optionally, specify location bounds to
          // limit which vehicles are
          // retrieved and immediately start tracking.
          locationRestriction: {
            north: 37.3,
            east: -121.8,
            south: 37.1,
            west: -122,
          },
          // Optionally, specify a filter to limit
          // which vehicles are retrieved.
          vehicleFilter:
            'attributes.foo = "bar" AND attributes.baz = "qux"',
        });

TypeScript

locationProvider =
    new google.maps.journeySharing
        .FleetEngineFleetLocationProvider({
          projectId,
          authTokenFetcher,

          // Optionally, specify location bounds to
          // limit which vehicles are
          // retrieved and immediately start tracking.
          locationRestriction: {
            north: 37.3,
            east: -121.8,
            south: 37.1,
            west: -122,
          },
          // Optionally, specify a filter to limit
          // which vehicles are retrieved.
          vehicleFilter:
            'attributes.foo = "bar" AND attributes.baz = "qux"',
        });

शेड्यूल किए गए टास्क

JavaScript

locationProvider =
    new google.maps.journeySharing
        .FleetEngineDeliveryFleetLocationProvider({
          projectId,
          authTokenFetcher,

          // Optionally, specify location bounds to
          // limit which delivery vehicles are
          // retrieved and immediately make the location provider active.
          locationRestriction: {
            north: 37.3,
            east: -121.8,
            south: 37.1,
            west: -122,
          },
          // Optionally, specify a filter to limit
          // which delivery vehicles are retrieved.
          deliveryVehicleFilter:
            'attributes.foo = "bar" AND attributes.baz = "qux"',
        });

TypeScript

locationProvider =
    new google.maps.journeySharing
        .FleetEngineDeliveryFleetLocationProvider({
          projectId,
          authTokenFetcher,

          // Optionally, specify location bounds to
          // limit which delivery vehicles are
          // retrieved and immediately make the location provider active.
          locationRestriction: {
            north: 37.3,
            east: -121.8,
            south: 37.1,
            west: -122,
          },
          // Optionally, specify a filter to limit
          // which delivery vehicles are retrieved.
          deliveryVehicleFilter:
            'attributes.foo = "bar" AND attributes.baz = "qux"',
        });

कंस्ट्रक्टर के बाद, locationRestriction को सेट करने के लिए, इस रूप में अपने कोड में locationProvider.locationRestriction बाद नीचे दिए गए JavaScript उदाहरण में दिखाया गया है.

   // You can choose to not set locationRestriction in the constructor.
   // In this case, the location provider *DOES NOT START* after this line, because
   // no locationRestriction is set.
   locationProvider = new google.maps.journeySharing.DeliveryFleetLocationProvider({
   ... // not setting locationRestriction here
   });

   // You can then set the locationRestriction *after* the constructor.
   // After this line, the location provider is active.
   locationProvider.locationRestriction = {
     north: 1,
     east: 2,
     south: 0,
     west: 1,
   };

मैप व्यूपोर्ट का इस्तेमाल करके जगह की पाबंदी सेट करें

मौजूदा इलाके के हिसाब से locationRestriction सीमाएं भी सेट की जा सकती हैं मैप दृश्य में दृश्यमान होता है.

मांग पर यात्राएं

JavaScript

google.maps.event.addListenerOnce(
  mapView.map, 'bounds_changed', () => {
    const bounds = mapView.map.getBounds();
    if (bounds) {
      // If you did not specify a location restriction in the
      // location provider constructor, you may do so here.
      // Location tracking will start as soon as this is set.
      locationProvider.locationRestriction = bounds;
    }
  });

TypeScript

google.maps.event.addListenerOnce(
  mapView.map, 'bounds_changed', () => {
    const bounds = mapView.map.getBounds();
    if (bounds) {
      // If you did not specify a location restriction in the
      // location provider constructor, you may do so here.
      // Location tracking will start as soon as this is set.
      locationProvider.locationRestriction = bounds;
    }
  });

शेड्यूल किए गए टास्क

JavaScript

google.maps.event.addListenerOnce(
  mapView.map, 'bounds_changed', () => {
    const bounds = mapView.map.getBounds();
    if (bounds) {
      // If you did not specify a location restriction in the
      // location provider constructor, you may do so here.
      // Location provider will start as soon as this is set.
      locationProvider.locationRestriction = bounds;
    }
  });

TypeScript

google.maps.event.addListenerOnce(
  mapView.map, 'bounds_changed', () => {
    const bounds = mapView.map.getBounds();
    if (bounds) {
      // If you did not specify a location restriction in the
      // location provider constructor, you may do so here.
      // Location provider will start as soon as this is set.
      locationProvider.locationRestriction = bounds;
    }
  });

मैप व्यू शुरू करें

जब आप लोकेशन प्रोवाइडर बना लें, तब मैप व्यू को उसी ट्रैक करने का एक तरीका है.

JavaScript की गतिविधि शेयर करने की लाइब्रेरी लोड करने के बाद, शुरू करें मैप व्यू में जोड़ सकते हैं और उसे एचटीएमएल पेज में जोड़ सकते हैं. आपके पेज में यह होना चाहिए एक <div> एलिमेंट जिसमें मैप व्यू शामिल होता है. <div> एलिमेंट नीचे दिए गए उदाहरणों में map_canvas नाम दिया गया है.=

मांग पर यात्राएं

JavaScript

const mapView = new
    google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [locationProvider],
});

// If you did not specify a vehicle ID in the
// location provider constructor, you may do so here.
// Location tracking will start as soon as this is set.
locationProvider.vehicleId
                        = 'your-vehicle-id';

// Give the map an initial viewport to allow it to
// initialize; otherwise the 'ready' event above may
// not fire. The user also has access to the mapView
// object to customize as they want.
mapView.map.setCenter('Times Square, New York, NY');
mapView.map.setZoom(14);

TypeScript

const mapView = new
    google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [locationProvider],
});

// If you did not specify a vehicle ID in the
// location provider constructor, you may do so here.
// Location tracking will start as soon as this is set.
locationProvider.VehicleId
                        = 'your-vehicle-id';

// Give the map an initial viewport to allow it to
// initialize; otherwise the 'ready' event above may
// not fire. The user also has access to the mapView
// object to customize as they want.
mapView.map.setCenter('Times Square, New York, NY');
mapView.map.setZoom(14);

शेड्यूल किए गए टास्क

JavaScript

const mapView = new
    google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [locationProvider],
});

// If you did not specify a delivery vehicle ID in the
// location provider constructor, you may do so here.
// Location tracking will start as soon as this is set.
locationProvider.deliveryVehicleId
                        = 'your-delivery-vehicle-id';

// Give the map an initial viewport to allow it to
// initialize; otherwise the 'ready' event above may
// not fire. The user also has access to the mapView
// object to customize as they want.
mapView.map.setCenter('Times Square, New York, NY');
mapView.map.setZoom(14);

TypeScript

const mapView = new
    google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [locationProvider],
});

// If you did not specify a delivery vehicle ID in the
// location provider constructor, you may do so here.
// Location tracking will start as soon as this is set.
locationProvider.deliveryVehicleId
                        = 'your-delivery-vehicle-id';

// Give the map an initial viewport to allow it to
// initialize; otherwise the 'ready' event above may
// not fire. The user also has access to the mapView
// object to customize as they want.
mapView.map.setCenter('Times Square, New York, NY');
mapView.map.setZoom(14);

इवेंट सुनें और गड़बड़ियां ठीक करें

सभी को फ़ॉलो करना शुरू करने के बाद, आपको इवेंट में होने वाले बदलावों को ध्यान से सुनना होगा और नीचे दिए गए सेक्शन में बताई गई गड़बड़ियों को ठीक करें.

बदलाव से जुड़े इवेंट सुनें

वाहन की ऑब्जेक्ट से, बेड़े के बारे में मेटा जानकारी हासिल की जा सकती है. इसके लिए, किसी दूसरे व्यक्ति की संपर्क जानकारी में शामिल हो सकता है. मेटा जानकारी में बदलाव होने पर अपडेट ट्रिगर होता है इवेंट. मेटा जानकारी में वाहन की प्रॉपर्टी शामिल हैं, जैसे कि नेविगेशन राज्य, बाकी दूरी, और कस्टम एट्रिब्यूट.

जानकारी के लिए, यहां दी गई जानकारी देखें:

नीचे दिए गए उदाहरणों में, बदलाव के इन इवेंट को सुनने का तरीका बताया गया है.

मांग पर यात्राएं

JavaScript

locationProvider.addListener('update', e => {
  // e.vehicles contains data that may be
  // useful to the rest of the UI.
  for (vehicle of e.vehicles) {
    console.log(vehicle.navigationStatus);
  }
});

TypeScript

locationProvider.addListener('update',
    (e: google.maps.journeySharing.FleetEngineFleetLocationProviderUpdateEvent) => {
  // e.vehicles contains data that may be
  // useful to the rest of the UI.
  if (e.vehicles) {
    for (vehicle of e.vehicles) {
      console.log(vehicle.navigationStatus);
    }
  }
});

शेड्यूल किए गए टास्क

JavaScript

locationProvider.addListener('update', e => {
  // e.deliveryVehicles contains data that may be
  // useful to the rest of the UI.
  if (e.deliveryVehicles) {
    for (vehicle of e.deliveryVehicles) {
      console.log(vehicle.remainingDistanceMeters);
    }
  }
});

TypeScript

locationProvider.addListener('update',
    (e: google.maps.journeySharing.FleetEngineDeliveryFleetLocationProviderUpdateEvent) => {
  // e.deliveryVehicles contains data that may be
  // useful to the rest of the UI.
  if (e.deliveryVehicles) {
    for (vehicle of e.deliveryVehicles) {
      console.log(vehicle.remainingDistanceMeters);
    }
  }
});

गड़बड़ियां सुनें

आप वाहन. वाहन का अनुरोध करने पर होने वाली गड़बड़ियां जानकारी ट्रिगर होने में गड़बड़ी हुई.

नीचे दिए गए उदाहरण में, इन इवेंट को रिकॉर्ड करना ज़रूरी है, ताकि आप गड़बड़ियां मैनेज कर सकें.

JavaScript

locationProvider.addListener('error', e => {
  // e.error is the error that triggered the event.
  console.error(e.error);
});

TypeScript

locationProvider.addListener('error', (e: google.maps.ErrorEvent) => {
  // e.error is the error that triggered the event.
  console.error(e.error);
});

फ़्लीट को ट्रैक करना बंद करें

फ़्लीट को ट्रैक करना बंद करने के लिए, जगह की जानकारी देने वाली कंपनी की सीमाओं को शून्य पर सेट करें, और फिर मैप व्यू से जगह की जानकारी देने वाले को हटा दें, जैसा कि सेक्शन पढ़ें.

जगह की जानकारी देने वाली कंपनी की सीमाओं को शून्य पर सेट करें

जगह की जानकारी देने वाली कंपनी को फ़्लीट को ट्रैक करने से रोकने के लिए, सीमाएं सेट करें अमान्य हो जाएगा.

मांग पर यात्राएं

JavaScript

locationProvider.locationRestriction = null;

TypeScript

locationProvider.locationRestriction = null;

शेड्यूल किए गए टास्क

JavaScript

locationProvider.locationRestriction = null;

TypeScript

locationProvider.locationRestriction = null;

मैप व्यू से, जगह की जानकारी देने वाली कंपनी को हटाएं

नीचे दिए गए उदाहरण में, मैप व्यू से जगह की जानकारी देने वाली कंपनी को हटाने का तरीका बताया गया है.

JavaScript

mapView.removeLocationProvider(locationProvider);

TypeScript

mapView.removeLocationProvider(locationProvider);

डिलीवरी फ़्लीट देखते समय, डिलीवरी वाहन को ट्रैक करें

अगर शेड्यूल किए गए टास्क के लिए मोबिलिटी सेवाओं का इस्तेमाल किया जा रहा है, तो आपके पास डिलीवरी करने वाले वाहन के लिए, रास्ते और आने वाले टास्क दिखाएं उसी मैप दृश्य में. ऐसा करने के लिए, डिलीवरी फ़्लीट लोकेशन को इंस्टैंशिएट करें सेवा देने वाली कंपनी और डिलीवरी वाहन की जगह की जानकारी देने वाली कंपनी. साथ ही, इन दोनों को मैप पर जोड़ें व्यू. इंस्टैंशिएट होने के बाद, डिलीवरी फ़्लीट की जगह की जानकारी देने वाली कंपनी दिखना शुरू हो जाती है डिलीवरी करने वाले वाहन मैप पर मौजूद हैं. नीचे दिए गए उदाहरणों में, इंस्टैंशिएट करने का तरीका बताया गया है दोनों लोकेशन प्रोवाइडर:

JavaScript

deliveryFleetLocationProvider =
    new google.maps.journeySharing
        .FleetEngineDeliveryFleetLocationProvider({
          projectId,
          authTokenFetcher,

          // Optionally, specify location bounds to
          // limit which delivery vehicles are
          // retrieved and immediately start tracking.
          locationRestriction: {
            north: 37.3,
            east: -121.8,
            south: 37.1,
            west: -122,
          },
          // Optionally, specify a filter to limit
          // which delivery vehicles are retrieved.
          deliveryVehicleFilter:
            'attributes.foo = "bar" AND attributes.baz = "qux"',
        });

deliveryVehicleLocationProvider =
    new google.maps.journeySharing
        .FleetEngineDeliveryVehicleLocationProvider({
          projectId,
          authTokenFetcher
        });

const mapView = new
    google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [
    deliveryFleetLocationProvider,
    deliveryVehicleLocationProvider,
  ],
  // Any other options
});

TypeScript

deliveryFleetLocationProvider =
    new google.maps.journeySharing
        .FleetEngineDeliveryFleetLocationProvider({
          projectId,
          authTokenFetcher,

          // Optionally, specify location bounds to
          // limit which delivery vehicles are
          // retrieved and immediately start tracking.
          locationRestriction: {
            north: 37.3,
            east: -121.8,
            south: 37.1,
            west: -122,
          },
          // Optionally, specify a filter to limit
          // which delivery vehicles are retrieved.
          deliveryVehicleFilter:
            'attributes.foo = "bar" AND attributes.baz = "qux"',
        });

deliveryVehicleLocationProvider =
    new google.maps.journeySharing
        .FleetEngineDeliveryVehicleLocationProvider({
          projectId,
          authTokenFetcher
        });

const mapView = new
    google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [
    deliveryFleetLocationProvider,
    deliveryVehicleLocationProvider,
  ],
  // Any other options
});

डिलीवरी वाहन को ट्रैक करने के लिए, मार्कर को पसंद के मुताबिक बनाने की सुविधा का इस्तेमाल करें

डिलीवरी वाहन की जगह की जानकारी देने वाली कंपनी, डिलीवरी वाहन को ट्रैक कर सके जब आप उसका फ़्लीट मार्कर क्लिक करते हैं, तो इन चरणों का पालन करें:

  1. मार्कर को पसंद के मुताबिक बनाएं और क्लिक करने के लिए कोई कार्रवाई जोड़ें.

  2. डुप्लीकेट मार्कर से बचने के लिए मार्कर छिपाएं.

इन चरणों के उदाहरण नीचे दिए गए हैं.

मार्कर को पसंद के मुताबिक बनाएं और क्लिक करने के लिए कोई कार्रवाई जोड़ें

JavaScript

// Specify the customization function either separately, or as a field in
// the options for the delivery fleet location provider constructor.
deliveryFleetLocationProvider.deliveryVehicleMarkerCustomization =
  (params) => {
    if (params.isNew) {
      params.marker.addListener('click', () => {
        // params.vehicle.name follows the format
        // "providers/{provider}/deliveryVehicles/{vehicleId}".
        // Only the vehicleId portion is used for the delivery vehicle
        // location provider.
        deliveryVehicleLocationProvider.deliveryVehicleId =
            params.vehicle.name.split('/').pop();
      });
    }
  };

TypeScript

// Specify the customization function either separately, or as a field in
// the options for the delivery fleet location provider constructor.
deliveryFleetLocationProvider.deliveryVehicleMarkerCustomization =
  (params: google.maps.journeySharing.DeliveryVehicleMarkerCustomizationFunctionParams) => {
    if (params.isNew) {
      params.marker.addListener('click', () => {
        // params.vehicle.name follows the format
        // "providers/{provider}/deliveryVehicles/{vehicleId}".
        // Only the vehicleId portion is used for the delivery vehicle
        // location provider.
        deliveryVehicleLocationProvider.deliveryVehicleId =
            params.vehicle.name.split('/').pop();
      });
    }
  };

डुप्लीकेट मार्कर से बचने के लिए मार्कर छिपाएं

रेंडरिंग रोकने के लिए, मार्कर को डिलीवरी वाले वाहन की जगह की जानकारी देने वाली कंपनी से छिपाएं एक ही वाहन के लिए दो मार्कर:

JavaScript

// Specify the customization function either separately, or as a field in
// the options for the delivery vehicle location provider constructor.
deliveryVehicleLocationProvider.deliveryVehicleMarkerCustomization =
  (params) => {
    if (params.isNew) {
      params.marker.setVisible(false);
    }
  };

TypeScript

// Specify the customization function either separately, or as a field in
// the options for the delivery vehicle location provider constructor.
deliveryVehicleLocationProvider.deliveryVehicleMarkerCustomization =
  (params: deliveryVehicleMarkerCustomizationFunctionParams) => {
    if (params.isNew) {
      params.marker.setVisible(false);
    }
  };

आगे क्या करना है