Tài liệu này trình bày cách tuỳ chỉnh giao diện của bản đồ và kiểm soát chế độ hiển thị dữ liệu cũng như các lựa chọn về khung hiển thị. Bạn có thể thực hiện việc này theo các cách sau:
Sử dụng tính năng định kiểu bản đồ dựa trên đám mây
Đặt các lựa chọn về kiểu bản đồ ngay trong mã của riêng bạn
Tạo kiểu cho bản đồ bằng tính năng định kiểu bản đồ dựa trên đám mây
Để áp dụng một kiểu bản đồ cho bản đồ chia sẻ chuyến đi của người dùng JavaScript, hãy chỉ định một mapId và mọi mapOptions khác khi bạn tạo JourneySharingMapView.
Các ví dụ sau đây cho thấy cách áp dụng một kiểu bản đồ bằng mã bản đồ.
JavaScript
constmapView=newgoogle.maps.journeySharing.JourneySharingMapView({element:document.getElementById('map_canvas'),locationProviders:[locationProvider],mapOptions:{mapId:'YOUR_MAP_ID'}// Any other styling options.});
TypeScript
constmapView=newgoogle.maps.journeySharing.JourneySharingMapView({element:document.getElementById('map_canvas'),locationProviders:[locationProvider],mapOptions:{mapId:'YOUR_MAP_ID'}// Any other styling options.});
Tạo kiểu cho bản đồ ngay trong mã của riêng bạn
Bạn cũng có thể tuỳ chỉnh kiểu bản đồ bằng cách đặt các lựa chọn về bản đồ khi tạo JourneySharingMapView. Các ví dụ sau đây minh hoạ cách tạo kiểu cho bản đồ bằng cách sử dụng các lựa chọn về bản đồ. Để biết thêm thông tin về những lựa chọn mà bạn có thể đặt cho bản đồ, hãy xem mapOptions trong tài liệu tham khảo về API JavaScript của Google Maps.
Hiển thị thông tin bổ sung về một phương tiện hoặc điểm đánh dấu vị trí bằng cách sử dụng InfoWindow. Để biết thêm thông tin, hãy xem InfoWindow.
Ví dụ sau đây cho thấy cách tạo một InfoWindow và đính kèm InfoWindow đó vào một điểm đánh dấu xe:
JavaScript
// 1. Create an info window.constinfoWindow=newgoogle.maps.InfoWindow({disableAutoPan:true});locationProvider.addListener('update',e=>{conststopsCount=e.trip.remainingWaypoints.length;infoWindow.setContent(`Your vehicle is ${stopsCount} stops away.`);// 2. Attach the info window to a vehicle marker.// This property can return multiple markers.constmarker=mapView.vehicleMarkers[0];infoWindow.open(mapView.map,marker);});// 3. Close the info window.infoWindow.close();
TypeScript
// 1. Create an info window.constinfoWindow=newgoogle.maps.InfoWindow({disableAutoPan:true});locationProvider.addListener('update',(e:google.maps.journeySharing.FleetEngineTripLocationProviderUpdateEvent)=>{conststopsCount=e.trip.remainingWaypoints.length;infoWindow.setContent(`Your vehicle is ${stopsCount} stops away.`);// 2. Attach the info window to a vehicle marker.// This property can return multiple markers.constmarker=mapView.vehicleMarkers[0];infoWindow.open(mapView.map,marker);});// 3. Close the info window.infoWindow.close();
Tắt tính năng tự động điều chỉnh
Bạn có thể ngăn bản đồ tự động điều chỉnh khung hiển thị cho phù hợp với xe và tuyến đường dự kiến bằng cách tắt chế độ tự động điều chỉnh. Ví dụ sau đây cho thấy cách tắt tính năng tự động điều chỉnh khi bạn định cấu hình chế độ xem bản đồ chia sẻ hành trình.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-17 UTC."],[[["\u003cp\u003eThis documentation explains how to customize the appearance of maps in journey sharing by using cloud-based map styling or setting style options directly in your code.\u003c/p\u003e\n"],["\u003cp\u003eYou can style maps using cloud-based map styling through the Google Cloud console or by setting style options in your code for \u003ccode\u003eConsumerMapView\u003c/code\u003e and \u003ccode\u003eConsumerMapFragment\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIn JavaScript, you can style your consumer trip sharing map by specifying a \u003ccode\u003emapId\u003c/code\u003e and other \u003ccode\u003emapOptions\u003c/code\u003e when creating the \u003ccode\u003eJourneySharingMapView\u003c/code\u003e, or by directly setting map options in your code.\u003c/p\u003e\n"],["\u003cp\u003eYou can display additional information using \u003ccode\u003eInfoWindow\u003c/code\u003e, and control the viewport by disabling automatic fitting to the vehicle and route.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/mobility/journey-sharing/on-demand/android/style \"View this page for the Android platform docs.\") [iOS](/maps/documentation/mobility/journey-sharing/on-demand/ios/style \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/mobility/journey-sharing/on-demand/javascript/style \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nThis document covers how to customize the look and feel of a map and control\ndata visibility and viewport options. You can do this in the following ways:\n\n- Use cloud-based map styling\n- Set map style options directly in your own code\n\nStyle the map with cloud-based maps styling\n\nTo apply a map style to your JavaScript consumer trip sharing map, specify a\n[`mapId`](/maps/documentation/javascript/reference/map#MapOptions.mapId) and\nany other\n[`mapOptions`](/maps/documentation/javascript/reference/map#MapOptions)\nwhen you create the `JourneySharingMapView`.\n| **Note:** You cannot change or add a `mapId` after the `JourneySharingMapView` has been instantiated.\n\nThe following examples show how to apply a map style with a map ID.\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n const mapView = new google.maps.journeySharing.JourneySharingMapView({\n element: document.getElementById('map_canvas'),\n locationProviders: [locationProvider],\n mapOptions: {\n mapId: 'YOUR_MAP_ID'\n }\n // Any other styling options.\n });\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n const mapView = new google.maps.journeySharing.JourneySharingMapView({\n element: document.getElementById('map_canvas'),\n locationProviders: [locationProvider],\n mapOptions: {\n mapId: 'YOUR_MAP_ID'\n }\n // Any other styling options.\n });\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nStyle maps directly in your own code\n\nYou can also customize map styling by setting map options when you create the\n`JourneySharingMapView`. The following examples show how to style a map using\nmap options. For more information on what map options you can set, see\n[`mapOptions`](/maps/documentation/javascript/reference/map#MapOptions)\nin the Google Maps JavaScript API reference.\n\n\u003cbr /\u003e\n\nJavaScript\n\n\u003cbr /\u003e\n\n const mapView = new google.maps.journeySharing.JourneySharingMapView({\n element: document.getElementById('map_canvas'),\n locationProviders: [locationProvider],\n mapOptions: {\n styles: [\n {\n \"featureType\": \"road.arterial\",\n \"elementType\": \"geometry\",\n \"stylers\": [\n { \"color\": \"#CCFFFF\" }\n ]\n }\n ]\n }\n });\n\n\u003cbr /\u003e\n\nTypeScript\n\n\u003cbr /\u003e\n\n const mapView = new google.maps.journeySharing.JourneySharingMapView({\n element: document.getElementById('map_canvas'),\n locationProviders: [locationProvider],\n mapOptions: {\n styles: [\n {\n \"featureType\": \"road.arterial\",\n \"elementType\": \"geometry\",\n \"stylers\": [\n { \"color\": \"#CCFFFF\" }\n ]\n }\n ]\n }\n });\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nDisplay information on the map\n\nDisplay additional information about a vehicle or location marker using an\n`InfoWindow`. For more information, see\n[`InfoWindow`](/maps/documentation/javascript/infowindows).\n\nThe following example shows how to create an `InfoWindow` and attach it\nto a vehicle marker: \n\nJavaScript \n\n // 1. Create an info window.\n const infoWindow = new google.maps.InfoWindow(\n {disableAutoPan: true});\n\n locationProvider.addListener('update', e =\u003e {\n const stopsCount = e.trip.remainingWaypoints.length;\n infoWindow.setContent(\n `Your vehicle is ${stopsCount} stops away.`);\n\n // 2. Attach the info window to a vehicle marker.\n // This property can return multiple markers.\n const marker = mapView.vehicleMarkers[0];\n infoWindow.open(mapView.map, marker);\n });\n\n // 3. Close the info window.\n infoWindow.close();\n\nTypeScript \n\n // 1. Create an info window.\n const infoWindow = new google.maps.InfoWindow(\n {disableAutoPan: true});\n\n locationProvider.addListener('update', (e: google.maps.journeySharing.FleetEngineTripLocationProviderUpdateEvent) =\u003e {\n const stopsCount = e.trip.remainingWaypoints.length;\n infoWindow.setContent(\n `Your vehicle is ${stopsCount} stops away.`);\n\n // 2. Attach the info window to a vehicle marker.\n // This property can return multiple markers.\n const marker = mapView.vehicleMarkers[0];\n infoWindow.open(mapView.map, marker);\n });\n\n // 3. Close the info window.\n infoWindow.close();\n\nDisable automatic fitting\n\nYou can stop the map from automatically fitting the viewport to the vehicle\nand anticipated route by disabling automatic fitting. The following example\nshows how to disable automatic fitting when you configure the journey sharing\nmap view. \n\nJavaScript \n\n const mapView = new\n google.maps.journeySharing.JourneySharingMapView({\n element: document.getElementById('map_canvas'),\n locationProviders: [locationProvider],\n automaticViewportMode:\n google.maps.journeySharing\n .AutomaticViewportMode.NONE,\n ...\n });\n\nTypeScript \n\n const mapView = new\n google.maps.journeySharing.JourneySharingMapView({\n element: document.getElementById('map_canvas'),\n locationProviders: [locationProvider],\n automaticViewportMode:\n google.maps.journeySharing\n .AutomaticViewportMode.NONE,\n ...\n });\n\nWhat's next\n\n[Customize markers](/maps/documentation/mobility/journey-sharing/on-demand/javascript/customize-markers)"]]