קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
במסמך הזה מפורטים שדות חשובים של כלי רכב שאפשר לעדכן כשיוצרים ומנהלים כלי רכב.
type: סוג כלי המסירה הזה. השינוי הזה משפיע על המסלולים שנוצרים לרכב הזה.
attributes[]: מערך אופציות מסוג
DeliveryVehicleAttribute. אפשר להשתמש בהם כדי להגדיר קריטריונים מותאמים אישית לכלי רכב בשירות שלכם, וכך לשפר את התנהגות הסינון כשמחפשים או מציגים כלי רכב.
אפשר להשתמש בשדה attributesכלי רכב כדי ליצור קריטריונים מותאמים אישית שיאפשרו ללקוחות או למנהלי צי רכב למצוא כלי רכב בצי לפי מגוון רחב יותר של קריטריונים לחיפוש. כך משפרים את היכולות של האפליקציות לספק התאמות טובות יותר של כלי רכב בהשוואה למה שהיה מתקבל משימוש בקריטריונים לחיפוש שמבוססים רק על שדות אחרים של כלי רכב. לכל רכב יכולים להיות עד 100 מאפיינים, וכל אחד מהם חייב להיות בעל מפתח ייחודי. הערכים יכולים להיות מחרוזות, ערכים בוליאניים או מספרים.
לדוגמה, אפשר להצהיר על מאפיין מותאם אישית בשם zone כדי להבחין בין האזורים בעיר שבהם פועלים כלי הרכב שלכם למשלוחים. כדי לייצג אזורים שונים, אפשר להשתמש בערכי מחרוזת כמו 1B, 2C ו-3A. לאחר מכן, תוכלו להשתמש במסנן במעקב אחר צי הרכב כדי להציג רק את כלי הרכב שפועלים באזור מסוים לאחראי על האזור הזה.
עם זאת, ערכי מאפיינים מותאמים אישית לא חייבים להיות ייחודיים. אפשר להשתמש בקריטריונים כמו available-at-night (זמין בלילה) ו-has-refrigeration (יש קירור). כל אחד מהם יכול להיות מאפיין מותאם אישית נפרד שמשתמש בערכים בוליאניים. לרכב מסוים אפשר להקצות את כל שלושת המאפיינים המותאמים אישית האלה, יחד עם המאפיין המותאם אישית אזור שמוגדר לערך המחרוזת המתאים.
עדכון מאפייני הרכב
לכל מפתח attributes יכול להיות רק ערך אחד לכל רכב. מצהירים על מאפייני רכב מותאמים אישית באמצעות attributes במסכת השדות, ואז מספקים ערכים לפי השיטה שבהמשך.
אי אפשר לעדכן רק מאפיין אחד באמצעות ה-API UpdateDeliveryVehicle. כשמשתמשים בשיטה הזו, כל שימוש בשדה attributes במסכת השדות גורם להצהרה מחדש של כל קבוצת מאפייני הרכב. כתוצאה מכך, כל מאפיין קיים שלא נכלל במפורש במסכת השדה יימחק. אם משתמשים בשיטה הזו כדי להצהיר על מאפיין מותאם אישית חדש, צריך גם להצהיר מחדש על כל מאפיין מותאם אישית שרוצים שהרכב ישמור. אם לא כוללים את attributes במסכת השדות, השיטה הזו משאירה את המאפיינים הקיימים של הרכב כפי שהוגדרו קודם.
אם משתמשים ב-attributes במסכת השדות, אבל בלי להגדיר ערכים, זה שווה להסרת כל המאפיינים המותאמים אישית של הרכב.
דוגמה לעדכון שדות של כלי רכב
בקטע הזה מוסבר איך לעדכן שדות של רכבים באמצעות UpdateDeliveryVehicleRequest, שכולל update_mask כדי לציין אילו שדות לעדכן. פרטים נוספים מופיעים במסמכי התיעוד של Protocol Buffers בנושא field masks.
כדי לעדכן שדות אחרים מלבד last_location, נדרשות הרשאות אדמין של Fleet Engine Delivery.
דוגמה: הגדרת מאפיין מותאם אישית
בדוגמה הזו מצוין מאפיין חדש: zone. כמו שצוין במאמר עדכון מאפייני רכב, אם משתמשים בגישה הזו כדי לעדכן את השדה attributes, צריך לציין את כל המאפיינים המותאמים אישית שרוצים לשמור.
לכן בדוגמה מוצג ערך available-at-night שנכתב כדי למנוע את הדריסה שלו במהלך פעולת עדכון שבה מצוין השדה attributes.
staticfinalStringPROJECT_ID="my-delivery-co-gcp-project";staticfinalStringVEHICLE_ID="vehicle-8241890";DeliveryServiceBlockingStubdeliveryService=DeliveryServiceGrpc.newBlockingStub(channel);// Vehicle settingsStringvehicleName="providers/"+PROJECT_ID+"/deliveryVehicles/"+VEHICLE_ID;DeliveryVehiclemyDeliveryVehicle=DeliveryVehicle.newBuilder().addAllAttributes(ImmutableList.of(DeliveryVehicleAttribute.newBuilder().setKey("zone").setValue("1B").build(),DeliveryVehicleAttribute.newBuilder().setKey("available-at-night").setValue("true").build())).build();// DeliveryVehicle requestUpdateDeliveryVehicleRequestupdateDeliveryVehicleRequest=UpdateDeliveryVehicleRequest.newBuilder()// No need for the header.setName(vehicleName).setDeliveryVehicle(myDeliveryVehicle).setUpdateMask(FieldMask.newBuilder().addPaths("attributes")).build();try{DeliveryVehicleupdatedDeliveryVehicle=deliveryService.updateDeliveryVehicle(updateDeliveryVehicleRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseNOT_FOUND:break;casePERMISSION_DENIED:break;}return;}
REST
# Set JWT, PROJECT_ID, VEHICLE_ID, TASK1_ID, and TASK2_ID in the local# environmentcurl-XPATCH"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}?updateMask=attributes"\-H"Content-type: application/json"\-H"Authorization: Bearer ${JWT}"\--data-binary@- << EOM
{"attributes":[{"key":"zone","value":"1B"},
{"key":"available-at-night","value":"true"}]}EOM
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-05 (שעון UTC)."],[[["\u003cp\u003eThis document explains how to update vehicle fields, focusing on the \u003ccode\u003eattributes\u003c/code\u003e field for creating custom criteria to search and filter vehicles.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eattributes\u003c/code\u003e field allows you to define custom criteria for vehicles, such as zone or availability, to enhance search and filtering capabilities.\u003c/p\u003e\n"],["\u003cp\u003eWhen updating the \u003ccode\u003eattributes\u003c/code\u003e field, the entire set of attributes is re-declared, overwriting any pre-existing attribute not explicitly included.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example demonstrates how to update vehicle fields, including setting custom attributes using the \u003ccode\u003eUpdateDeliveryVehicle\u003c/code\u003e API.\u003c/p\u003e\n"],["\u003cp\u003eUpdating fields other than \u003ccode\u003elast_location\u003c/code\u003e requires Fleet Engine Delivery Admin privileges.\u003c/p\u003e\n"]]],["Before creating vehicle requests, review the requirements. You can manage vehicle fields like `type` and `attributes[]`. Attributes allow custom criteria for filtering, supporting strings, booleans, or numbers, each vehicle can have up to 100 attributes, with unique keys. Updating attributes overwrites the entire set; all desired attributes must be re-declared. The `update_mask` should always be set to specify what is being updated. There are gRPC and REST examples to set a custom attribute for a vehicle.\n"],null,["| **Note:** **Before constructing a vehicle request** , read the requirements under [Vehicle requests](/maps/documentation/mobility/fleet-engine/essentials/vehicles#vehicle_requests) in the Introduction.\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| This document covers important vehicle fields you can update when creating and managing vehicles. - `type`: The type of this delivery vehicle. This impacts routes generated for this vehicle. - `attributes[]`: An option array of type [`DeliveryVehicleAttribute`](/maps/documentation/mobility/fleet-engine/reference/tasks/rpc/maps.fleetengine.delivery.v1#maps.fleetengine.delivery.v1.DeliveryVehicleAttribute). Use them to define custom criteria for vehicles in your service to enhance filtering behavior when searching or listing vehicles. | | For a complete list of vehicle fields, see: - [`DeliveryVehicle message`](/maps/documentation/mobility/fleet-engine/reference/tasks/rpc/maps.fleetengine.delivery.v1#deliveryvehicle) - [`DeliveryVehicle resource`](/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/providers.deliveryVehicles) |\n\nVehicle attributes field\n\nUse the vehicle `attributes` field to create customized criteria to enable your\nconsumers or fleet operators to find vehicles in your fleet across a wider\nvariety of search criteria. This enhances the capabilities of your apps to\nprovide better vehicle matches over what you would from using search criteria\nbased solely on other vehicle fields. Each vehicle can have at most 100\nattributes, and each one must have a unique key. Values can be strings,\nbooleans, or numbers.\n\nFor example, you could declare a custom attribute called *zone* to\ndifferentiate which zone of the city your delivery vehicles operate in. You'd\nuse string values such as the following to represent different zones: `1B`,\n`2C`, and `3A`. You could then use a filter in Fleet Tracking to only show\nvehicles working in a specific zone to the operator responsible for that zone.\n\nHowever, custom attribute values don't have to be mutually exclusive. You might\nuse criteria such as *available-at-night* and *has-refrigeration* . Each of these\ncould be a separate custom attribute that uses boolean values. A given vehicle\ncould be assigned all three of these custom attributes along with the *zone*\ncustom attribute set to the appropriate string value.\n\nUpdate vehicle attributes\n\nEach `attributes` key can only have one value **per vehicle** . You declare\ncustom vehicle attributes using the `attributes` in the field mask, and then\nproviding values based on the method below.\n\nThis `UpdateDeliveryVehicle` API does not allow updating only a single\nattribute. When using this method, any use of the `attributes` field in the\nfield mask results in the **entire set** of vehicle attributes being re-declared\nfor the vehicle. This results in an overwrite of any pre-existing attribute not\nexplicitly included in the field mask. If you use this method to declare a new\ncustom attribute, you must also re-declare every custom attribute you want the\nvehicle to retain. If you exclude the `attributes` in the field mask, then this\nmethod leaves existing custom attributes as previously defined for the vehicle.\nIf you use `attributes` in the field mask, but without setting values, that is\nequivalent to removing all custom attributes from the vehicle.\n\nUpdate vehicle fields example\n\nThis section shows how to update vehicle fields using\n`UpdateDeliveryVehicleRequest`, which includes an `update_mask` to indicate\nwhich fields to update. See the Protocol Buffers documentation on\n[field masks](/maps/documentation/mobility/fleet-engine/essentials/vehicles/protobuf.dev/reference/cpp/api-docs/google.protobuf.util.field_mask_util) for details.\n| **Note:** The `update_mask` field should always be set. Not setting the `update_mask` field defaults to writing all fields. This can result in unintended behavior.\n\nUpdates to fields other than `last_location` require *Fleet Engine Delivery\nAdmin* privileges.\n\nExample: set custom attribute\n\nThis example specifies a new attribute: `zone`. As noted in\n[Update vehicle attributes](#update_vehicle_attributes) earlier, updating the `attributes` field using\nthis approach requires you to indicate all custom attributes you want to retain.\nTherefore the example shows a `available-at-night` value written to preserve it\nfrom being overwritten during an update operation that specifies the\n`attributes` field.\n\nSee the [providers.deliveryVehicles.patch](/maps/documentation/mobility/fleet-engine/reference/tasks/rest/v1/providers.deliveryVehicles/patch) reference. \n\ngRPC \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String VEHICLE_ID = \"vehicle-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Vehicle settings\n String vehicleName = \"providers/\" + PROJECT_ID + \"/deliveryVehicles/\" + VEHICLE_ID;\n DeliveryVehicle myDeliveryVehicle = DeliveryVehicle.newBuilder()\n .addAllAttributes(ImmutableList.of(\n DeliveryVehicleAttribute.newBuilder().setKey(\"zone\").setValue(\"1B\").build(),\n DeliveryVehicleAttribute.newBuilder().setKey(\"available-at-night\").setValue(\"true\").build()))\n .build();\n\n // DeliveryVehicle request\n UpdateDeliveryVehicleRequest updateDeliveryVehicleRequest =\n UpdateDeliveryVehicleRequest.newBuilder() // No need for the header\n .setName(vehicleName)\n .setDeliveryVehicle(myDeliveryVehicle)\n .setUpdateMask(FieldMask.newBuilder()\n .addPaths(\"attributes\"))\n .build();\n\n try {\n DeliveryVehicle updatedDeliveryVehicle =\n deliveryService.updateDeliveryVehicle(updateDeliveryVehicleRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nREST \n\n # Set JWT, PROJECT_ID, VEHICLE_ID, TASK1_ID, and TASK2_ID in the local\n # environment\n curl -X PATCH \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}?updateMask=attributes\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"attributes\": [\n {\"key\": \"zone\", \"value\": \"1B\"},\n {\"key\": \"available-at-night\", \"value\": \"true\"}\n ]\n }\n EOM\n\nWhat's next\n\n- [Update a delivery vehicle location](/maps/documentation/mobility/fleet-engine/essentials/vehicles/scheduled-tasks-update-vehicle-location)"]]