একটি মানচিত্র শৈলী

মানচিত্রের উপাদানটির চেহারা এবং অনুভূতি কাস্টমাইজ করতে, ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং ব্যবহার করে বা সরাসরি কোডে বিকল্পগুলি সেট করে আপনার মানচিত্রকে স্টাইল করুন।

ক্লাউড-ভিত্তিক মানচিত্রের স্টাইলিং দিয়ে মানচিত্রটিকে স্টাইল করুন

ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং ব্যবহার করে মানচিত্রের উপাদানটির চেহারা এবং অনুভূতি কাস্টমাইজ করুন। আপনি Google ক্লাউড কনসোলে আপনার যেকোনও অ্যাপের জন্য ম্যাপ স্টাইল তৈরি এবং সম্পাদনা করেন যা Google ম্যাপ ব্যবহার করে, আপনার কোডে কোনো পরিবর্তন না করেই। আরও তথ্যের জন্য, ক্লাউড-ভিত্তিক মানচিত্রের স্টাইলিং দেখুন।

ConsumerMapView এবং ConsumerMapFragment উভয় ক্লাসই ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং সমর্থন করে। ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং ব্যবহার করার জন্য, নিশ্চিত করুন যে নির্বাচিত মানচিত্র রেন্ডারার LATEST । নিম্নলিখিত বিভাগগুলি আপনার প্রকল্পের সাথে ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং কীভাবে ব্যবহার করবেন তার উদাহরণগুলি দেখায়৷

ConsumerMapView

ConsumerMapView এ ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং ব্যবহার করতে, GoogleMapOptionsmapId ক্ষেত্র সেট করুন এবং GoogleMapOptions (ConsumerMapReadyCallback, Fragment, GoogleMapOptions) বা getConsumerGoogleMapAsync,Mapt,All )

উদাহরণ

জাভা

public class SampleAppActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ConsumerMapView mapView = findViewById(R.id.consumer_map_view);

    if (mapView != null) {
      GoogleMapOptions optionsWithMapId = new GoogleMapOptions().mapId("map-id");
      mapView.getConsumerGoogleMapAsync(
          new ConsumerMapReadyCallback() {
            @Override
            public void onConsumerMapReady(@NonNull ConsumerGoogleMap consumerGoogleMap) {
              // ...
            }
          },
          /* fragmentActivity= */ this,
          /* googleMapOptions= */ optionsWithMapId);
    }
  }
}

কোটলিন

class SampleAppActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val mapView = findViewById(R.id.consumer_map_view) as ConsumerMapView

    val optionsWithMapId = GoogleMapOptions().mapId("map-id")
    mapView.getConsumerGoogleMapAsync(
      object : ConsumerGoogleMap.ConsumerMapReadyCallback() {
        override fun onConsumerMapReady(consumerGoogleMap: ConsumerGoogleMap) {
          // ...
        }
      },
      /* fragmentActivity= */ this,
      /* googleMapOptions= */ optionsWithMapId)
  }
}

ConsumerMapFragment

ConsumerMapFragments এ ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং ব্যবহার করার দুটি উপায় রয়েছে:

  • স্থিরভাবে এক্সএমএল দিয়ে।
  • newInstance সাথে গতিশীলভাবে।

স্থিরভাবে এক্সএমএল দিয়ে

ConsumerMapFragment এ XML-এর সাথে ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং ব্যবহার করতে, নির্দিষ্ট mapId এর সাথে map:mapId XML অ্যাট্রিবিউট যোগ করুন। নিম্নলিখিত উদাহরণ দেখুন:

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:name="com.google.android.libraries.mapsplatform.transportation.consumer.view.ConsumerMapFragment"
    android:id="@+id/consumer_map_fragment"
    map:mapId="map-id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

newInstance সাথে গতিশীলভাবে

ConsumerMapFragmentnewInstance এর সাথে ক্লাউড-ভিত্তিক মানচিত্র স্টাইলিং ব্যবহার করতে, GoogleMapOptionsmapId ক্ষেত্র সেট করুন এবং GoogleMapOptions newInstance এ পাস করুন। নিম্নলিখিত উদাহরণ দেখুন:

জাভা

public class SampleFragmentJ extends Fragment {

  @Override
  public View onCreateView(
      @NonNull LayoutInflater inflater,
      @Nullable ViewGroup container,
      @Nullable Bundle savedInstanceState) {

    final View view = inflater.inflate(R.layout.consumer_map_fragment, container, false);

    GoogleMapOptions optionsWithMapId = new GoogleMapOptions().mapId("map-id");
    ConsumerMapFragment consumerMapFragment = ConsumerMapFragment.newInstance(optionsWithMapId);

    getParentFragmentManager()
        .beginTransaction()
        .add(R.id.consumer_map_fragment, consumerMapFragment)
        .commit();

    consumerMapFragment.getConsumerGoogleMapAsync(
        new ConsumerMapReadyCallback() {
          @Override
          public void onConsumerMapReady(@NonNull ConsumerGoogleMap consumerGoogleMap) {
            // ...
          }
        });

    return view;
  }
}

কোটলিন

class SampleFragment : Fragment() {
  override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?): View? {

    val view = inflater.inflate(R.layout.consumer_map_fragment, container, false)

    val optionsWithMapId = GoogleMapOptions().mapId("map-id")
    val consumerMapFragment = ConsumerMapFragment.newInstance(optionsWithMapId)

    parentFragmentManager
      .beginTransaction()
      .add(R.id.consumer_map_fragment, consumerMapFragment)
      .commit()

    consumerMapFragment.getConsumerGoogleMapAsync(
      object : ConsumerMapReadyCallback() {
        override fun onConsumerMapReady(consumerGoogleMap: ConsumerGoogleMap) {
          // ...
        }
      })

    return view
  }
}

আপনার জাভাস্ক্রিপ্ট ভোক্তা যাত্রা ভাগাভাগি মানচিত্রে একটি মানচিত্র শৈলী প্রয়োগ করতে, আপনি যখন JourneySharingMapView তৈরি করবেন তখন একটি mapId এবং অন্য কোনো mapOptions উল্লেখ করুন।

নিম্নলিখিত উদাহরণগুলি দেখায় যে কীভাবে একটি মানচিত্র ID সহ একটি মানচিত্রের শৈলী প্রয়োগ করতে হয়।

জাভাস্ক্রিপ্ট

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

টাইপস্ক্রিপ্ট

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

আপনার নিজের কোডে সরাসরি স্টাইল মানচিত্র

আপনি যখন JourneySharingMapView তৈরি করেন তখন আপনি মানচিত্রের বিকল্পগুলি সেট করে মানচিত্রের স্টাইলিং কাস্টমাইজ করতে পারেন। নিম্নলিখিত উদাহরণগুলি দেখায় যে কীভাবে মানচিত্রের বিকল্পগুলি ব্যবহার করে একটি মানচিত্রের স্টাইল করা যায়। আপনি কোন মানচিত্রের বিকল্পগুলি সেট করতে পারেন সে সম্পর্কে আরও তথ্যের জন্য, Google মানচিত্র জাভাস্ক্রিপ্ট API রেফারেন্সে mapOptions দেখুন৷

জাভাস্ক্রিপ্ট

const mapView = new google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [locationProvider],
  mapOptions: {
    styles: [
      {
        "featureType": "road.arterial",
        "elementType": "geometry",
        "stylers": [
          { "color": "#CCFFFF" }
        ]
      }
    ]
  }
});

টাইপস্ক্রিপ্ট

const mapView = new google.maps.journeySharing.JourneySharingMapView({
  element: document.getElementById('map_canvas'),
  locationProviders: [locationProvider],
  mapOptions: {
    styles: [
      {
        "featureType": "road.arterial",
        "elementType": "geometry",
        "stylers": [
          { "color": "#CCFFFF" }
        ]
      }
    ]
  }
});

স্বয়ংক্রিয় ফিটিং অক্ষম করুন

আপনি স্বয়ংক্রিয় ফিটিং অক্ষম করে মানচিত্রটিকে গাড়ি এবং প্রত্যাশিত রুটে স্বয়ংক্রিয়ভাবে ভিউপোর্ট ফিট করা থেকে থামাতে পারেন। নিচের উদাহরণটি দেখায় কিভাবে আপনি যখন যাত্রা শেয়ারিং ম্যাপ ভিউ কনফিগার করেন তখন স্বয়ংক্রিয় ফিটিং অক্ষম করতে হয়।

জাভাস্ক্রিপ্ট

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

টাইপস্ক্রিপ্ট

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

একটি বিদ্যমান মানচিত্র প্রতিস্থাপন করুন

আপনি একটি বিদ্যমান মানচিত্র প্রতিস্থাপন করতে পারেন যাতে চিহ্নিতকারী বা অন্যান্য কাস্টমাইজেশনগুলি অন্তর্ভুক্ত থাকে সেই কাস্টমাইজেশনগুলি না হারিয়ে৷

উদাহরণস্বরূপ, ধরুন আপনার কাছে একটি মানক google.maps.Map সত্তা সহ একটি ওয়েব পৃষ্ঠা রয়েছে যেখানে একটি মার্কার দেখানো হয়েছে:

    <!DOCTYPE html>
    <html>
      <head>
        <style>
           /* Set the size of the div element that contains the map */
          #map {
            height: 400px;  /* The height is 400 pixels */
            width: 100%;  /* The width is the width of the web page */
           }
        </style>
      </head>
      <body>
        <h3>My Google Maps Demo</h3>
        <!--The div element for the map -->
        <div id="map"></div>
        <script>
    // Initialize and add the map
    function initMap() {
      // The location of Pier 39 in San Francisco
      var pier39 = {lat: 37.809326, lng: -122.409981};
      // The map, initially centered at Mountain View, CA.
      var map = new google.maps.Map(document.getElementById('map'));
      map.setOptions({center: {lat: 37.424069, lng: -122.0916944}, zoom: 14});

      // The marker, now positioned at Pier 39
      var marker = new google.maps.Marker({position: pier39, map: map});
    }
        </script>
        <!-- Load the API from the specified URL.
           * The async attribute allows the browser to render the page while the API loads.
           * The key parameter will contain your own API key (which is not needed for this tutorial).
           * The callback parameter executes the initMap() function.
        -->
        <script defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
        </script>
      </body>
    </html>

জাভাস্ক্রিপ্ট ফ্লিট ট্র্যাক লাইব্রেরি যোগ করতে:

  1. প্রমাণীকরণ টোকেন কারখানার জন্য কোড যোগ করুন।
  2. initMap() ফাংশনে একটি অবস্থান প্রদানকারী চালু করুন।
  3. initMap() ফাংশনে ম্যাপ ভিউ শুরু করুন। ভিউ মানচিত্র ধারণ করে.
  4. ম্যাপ ভিউ ইনিশিয়ালাইজেশনের জন্য কলব্যাক ফাংশনে আপনার কাস্টমাইজেশন সরান।
  5. API লোডারে অবস্থান লাইব্রেরি যোগ করুন।

নির্ধারিত কাজগুলি ব্যবহার করে মানচিত্র প্রতিস্থাপনের উদাহরণ

নিম্নলিখিত উদাহরণগুলি দেখায় কিভাবে একটি বিদ্যমান মানচিত্র ব্যবহার করতে হয় যেখানে আপনি একটি নির্ধারিত টাস্ক ব্যবহারের ক্ষেত্রে অবস্থান প্রদানকারী অবজেক্ট শুরু করেন। কোডটি অন-ডিমান্ড ট্রিপ ব্যবহারের ক্ষেত্রে একই রকম, আপনি FleetEngineDeliveryVehicleLocationProvider এর পরিবর্তে FleetEngineVehicleLocationProvider ব্যবহার করেন।

    <!DOCTYPE html>
    <html>
      <head>
        <style>
           /* Set the size of the div element that contains the map */
          #map {
            height: 400px;  /* The height is 400 pixels */
            width: 100%;  /* The width is the width of the web page */
           }
        </style>
      </head>
      <body>
        <h3>My Google Maps Demo</h3>
        <!--The div element for the map -->
        <div id="map"></div>
        <script>
    let locationProvider;

    // (1) Authentication Token Fetcher
    function authTokenFetcher(options) {
      // options is a record containing two keys called
      // serviceType and context. The developer should
      // generate the correct SERVER_TOKEN_URL and request
      // based on the values of these fields.
      const response = await fetch(SERVER_TOKEN_URL);
          if (!response.ok) {
            throw new Error(response.statusText);
          }
          const data = await response.json();
          return {
            token: data.Token,
            expiresInSeconds: data.ExpiresInSeconds
          };
    }

    // Initialize and add the map
    function initMap() {
      // (2) Initialize location provider. Use FleetEngineDeliveryVehicleLocationProvider
      // as appropriate.
      locationProvider = new google.maps.journeySharing.FleetEngineDeliveryVehicleLocationProvider({
        YOUR_PROVIDER_ID,
        authTokenFetcher,
      });

      // (3) Initialize map view (which contains the map).
      const mapView = new google.maps.journeySharing.JourneySharingMapView({
        element: document.getElementById('map'),
        locationProviders: [locationProvider],
        // any styling options
      });

    mapView.addListener('ready', () => {
      locationProvider.deliveryVehicleId = DELIVERY_VEHICLE_ID;

        // (4) Add customizations like before.
        // The location of Pier 39 in San Francisco
          var pier39 = {lat: 37.809326, lng: -122.409981};
        // The map, initially centered at Mountain View, CA.
        var map = mapView.map;
        map.setOptions({center: {lat: 37.424069, lng: -122.0916944}, zoom: 14});
        // The marker, now positioned at Pier 39
        var marker = new google.maps.Marker({position: pier39, map: map});
      };
    }
        </script>
        <!-- Load the API from the specified URL
          * The async attribute allows the browser to render the page while the API loads
          * The key parameter will contain your own API key (which is not needed for this tutorial)
          * The callback parameter executes the initMap() function
          *
          * (5) Add the journey sharing library to the API loader, which includes Fleet Tracking functionality.
        -->
        <script defer
        src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap&libraries=journeySharing">
        </script>
      </body>
    </html>

আপনি যদি Pier 39-এর কাছে নির্দিষ্ট আইডি সহ একটি ডেলিভারি গাড়ি চালান, তাহলে এটি এখন মানচিত্রে রেন্ডার করা হয়।

এরপর কি