চিহ্নিতকারী

প্ল্যাটফর্ম নির্বাচন করুন: অ্যান্ড্রয়েড আইওএস জাভাস্ক্রিপ্ট

ভূমিকা

একটি চিহ্নিতকারী একটি মানচিত্রে একটি অবস্থান সনাক্ত করে। ডিফল্টরূপে, একটি মার্কার একটি আদর্শ চিত্র ব্যবহার করে। মার্কারগুলি কাস্টম চিত্রগুলি প্রদর্শন করতে পারে, এই ক্ষেত্রে সেগুলি সাধারণত "আইকন" হিসাবে উল্লেখ করা হয়। মার্কার এবং আইকন হল Marker টাইপের বস্তু। আপনি মার্কার কনস্ট্রাক্টরের মধ্যে একটি কাস্টম আইকন সেট করতে পারেন, অথবা মার্কারে setIcon() কল করে। মার্কার ইমেজ কাস্টমাইজ করার বিষয়ে আরও দেখুন।

বিস্তৃতভাবে বলতে গেলে, মার্কার হল এক প্রকার ওভারলে। অন্যান্য ধরনের ওভারলে সম্পর্কে তথ্যের জন্য, মানচিত্রে অঙ্কন দেখুন।

মার্কারগুলি ইন্টারেক্টিভ হওয়ার জন্য ডিজাইন করা হয়েছে। উদাহরণস্বরূপ, ডিফল্টরূপে তারা 'click' ইভেন্টগুলি পায়, তাই আপনি কাস্টম তথ্য প্রদর্শন করে একটি তথ্য উইন্ডো আনতে একটি ইভেন্ট শ্রোতা যোগ করতে পারেন। আপনি মার্কারের draggable বৈশিষ্ট্যটিকে true সেট করে মানচিত্রে একটি মার্কার সরানোর অনুমতি দিতে পারেন৷ টেনে আনাযোগ্য মার্কার সম্পর্কে আরও তথ্যের জন্য, নীচে দেখুন।

একটি মার্কার যোগ করুন

google.maps.Marker কনস্ট্রাক্টর একটি একক Marker options অবজেক্ট আক্ষরিক নেয়, মার্কারটির প্রাথমিক বৈশিষ্ট্যগুলি নির্দিষ্ট করে৷

একটি মার্কার তৈরি করার সময় নিম্নলিখিত ক্ষেত্রগুলি বিশেষভাবে গুরুত্বপূর্ণ এবং সাধারণত সেট করা হয়:

  • position (প্রয়োজনীয়) একটি LatLng নির্দিষ্ট করে যা চিহ্নিত করে মার্কারের প্রাথমিক অবস্থান। একটি LatLng পুনরুদ্ধার করার একটি উপায় হল জিওকোডিং পরিষেবা ব্যবহার করা।
  • map (ঐচ্ছিক) Map নির্দিষ্ট করে যেটিতে মার্কার স্থাপন করতে হবে। আপনি যদি মার্কার নির্মাণে মানচিত্রটি নির্দিষ্ট না করেন, তাহলে মার্কার তৈরি করা হয় কিন্তু মানচিত্রের সাথে সংযুক্ত (বা প্রদর্শিত) হয় না। আপনি মার্কার setMap() পদ্ধতিতে কল করে পরে মার্কার যোগ করতে পারেন।

নিম্নলিখিত উদাহরণটি অস্ট্রেলিয়ার কেন্দ্রে উলুরুতে একটি মানচিত্রে একটি সাধারণ মার্কার যুক্ত করেছে:

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

function initMap(): void {
  const myLatLng = { lat: -25.363, lng: 131.044 };

  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 4,
      center: myLatLng,
    }
  );

  new google.maps.Marker({
    position: myLatLng,
    map,
    title: "Hello World!",
  });
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

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

function initMap() {
  const myLatLng = { lat: -25.363, lng: 131.044 };
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 4,
    center: myLatLng,
  });

  new google.maps.Marker({
    position: myLatLng,
    map,
    title: "Hello World!",
  });
}

window.initMap = initMap;
উদাহরণ দেখুন

নমুনা চেষ্টা করুন

উপরের উদাহরণে, মার্কার অপশনে map বৈশিষ্ট্য ব্যবহার করে মার্কার নির্মাণের সময় মার্কারটি মানচিত্রে স্থাপন করা হয়। বিকল্পভাবে, আপনি মার্কার setMap() পদ্ধতি ব্যবহার করে সরাসরি মানচিত্রে মার্কার যোগ করতে পারেন, যেমনটি নীচের উদাহরণে দেখানো হয়েছে:

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
  zoom: 4,
  center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);

var marker = new google.maps.Marker({
    position: myLatlng,
    title:"Hello World!"
});

// To add the marker to the map, call setMap();
marker.setMap(map);

The marker's title will appear as a tooltip.

If you do not wish to pass any Marker options in the marker's constructor, instead pass an empty object {} in the last argument of the constructor.

View example

Remove a marker

To remove a marker from the map, call the setMap() method passing null as the argument.

marker.setMap(null);

Note that the above method does not delete the marker. It removes the marker from the map. If instead you wish to delete the marker, you should remove it from the map, and then set the marker itself to null.

If you wish to manage a set of markers, you should create an array to hold the markers. Using this array, you can then call setMap() on each marker in the array in turn when you need to remove the markers. You can delete the markers by removing them from the map and then setting the array's length to 0, which removes all references to the markers.

View example

Customize a marker image

You can customize the visual appearance of markers by specifying an image file or vector-based icon to display instead of the default Google Maps pushpin icon. You can add text with a marker label, and use complex icons to define clickable regions, and set the stack order of markers.

Markers with image icons

In the most basic case, an icon can specify an image to use instead of the default Google Maps pushpin icon. To specify such an icon, set the marker's icon property to the URL of an image. The Maps JavaScript API will size the icon automatically.

TypeScript

// This example adds a marker to indicate the position of Bondi Beach in Sydney,
// Australia.
function initMap(): void {
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 4,
      center: { lat: -33, lng: 151 },
    }
  );

  const image =
    "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png";
  const beachMarker = new google.maps.Marker({
    position: { lat: -33.89, lng: 151.274 },
    map,
    icon: image,
  });
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

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

// This example adds a marker to indicate the position of Bondi Beach in Sydney,
// Australia.
function initMap() {
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 4,
    center: { lat: -33, lng: 151 },
  });
  const image =
    "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png";
  const beachMarker = new google.maps.Marker({
    position: { lat: -33.89, lng: 151.274 },
    map,
    icon: image,
  });
}

window.initMap = initMap;
উদাহরণ দেখুন

নমুনা চেষ্টা করুন

ভেক্টর-ভিত্তিক আইকন সহ মার্কার

মার্কারগুলির ভিজ্যুয়াল চেহারা নির্ধারণ করতে আপনি কাস্টম SVG ভেক্টর পাথ ব্যবহার করতে পারেন। এটি করার জন্য, মার্কার icon বৈশিষ্ট্যের পছন্দসই পথ সহ একটি Symbol বস্তু আক্ষরিক পাস করুন। আপনি SVG পাথ নোটেশন ব্যবহার করে একটি কাস্টম পাথ সংজ্ঞায়িত করতে পারেন, অথবা google.maps.SymbolPath- এ পূর্বনির্ধারিত পাথগুলির একটি ব্যবহার করতে পারেন৷ জুম স্তর পরিবর্তন হলে মার্কার সঠিকভাবে রেন্ডার করার জন্য anchor বৈশিষ্ট্য প্রয়োজন। মার্কার (এবং পলিলাইন) জন্য ভেক্টর-ভিত্তিক আইকন তৈরি করতে প্রতীক ব্যবহার সম্পর্কে আরও জানুন।

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

// This example uses SVG path notation to add a vector-based symbol
// as the icon for a marker. The resulting icon is a marker-shaped
// symbol with a blue fill and no border.

function initMap(): void {
  const center = new google.maps.LatLng(-33.712451, 150.311823);
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 9,
      center: center,
    }
  );

  const svgMarker = {
    path: "M-1.547 12l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM0 0q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
    fillColor: "blue",
    fillOpacity: 0.6,
    strokeWeight: 0,
    rotation: 0,
    scale: 2,
    anchor: new google.maps.Point(0, 20),
  };

  new google.maps.Marker({
    position: map.getCenter(),
    icon: svgMarker,
    map: map,
  });
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

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

// This example uses SVG path notation to add a vector-based symbol
// as the icon for a marker. The resulting icon is a marker-shaped
// symbol with a blue fill and no border.
function initMap() {
  const center = new google.maps.LatLng(-33.712451, 150.311823);
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 9,
    center: center,
  });
  const svgMarker = {
    path: "M-1.547 12l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM0 0q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
    fillColor: "blue",
    fillOpacity: 0.6,
    strokeWeight: 0,
    rotation: 0,
    scale: 2,
    anchor: new google.maps.Point(0, 20),
  };

  new google.maps.Marker({
    position: map.getCenter(),
    icon: svgMarker,
    map: map,
  });
}

window.initMap = initMap;
উদাহরণ দেখুন

নমুনা চেষ্টা করুন

মার্কার লেবেল

একটি মার্কার লেবেল একটি অক্ষর বা সংখ্যা যা একটি মার্কার ভিতরে প্রদর্শিত হয়। এই বিভাগে চিহ্নিতকারী চিত্রটি 'B' অক্ষর সহ একটি মার্কার লেবেল প্রদর্শন করে। আপনি একটি স্ট্রিং বা একটি MarkerLabel অবজেক্ট হিসাবে একটি মার্কার লেবেল নির্দিষ্ট করতে পারেন যাতে একটি স্ট্রিং এবং অন্যান্য লেবেল বৈশিষ্ট্য অন্তর্ভুক্ত থাকে।

একটি মার্কার তৈরি করার সময়, আপনি MarkerOptions অবজেক্টে একটি label বৈশিষ্ট্য নির্দিষ্ট করতে পারেন। বিকল্পভাবে, আপনি একটি বিদ্যমান মার্কারে লেবেল সেট করতে মার্কার অবজেক্টে setLabel() কল করতে পারেন।

নিম্নলিখিত উদাহরণটি লেবেলযুক্ত মার্কারগুলি প্রদর্শন করে যখন ব্যবহারকারী মানচিত্রে ক্লিক করেন:

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

// In the following example, markers appear when the user clicks on the map.
// Each marker is labeled with a single alphabetical character.
const labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let labelIndex = 0;

function initMap(): void {
  const bangalore = { lat: 12.97, lng: 77.59 };
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 12,
      center: bangalore,
    }
  );

  // This event listener calls addMarker() when the map is clicked.
  google.maps.event.addListener(map, "click", (event) => {
    addMarker(event.latLng, map);
  });

  // Add a marker at the center of the map.
  addMarker(bangalore, map);
}

// Adds a marker to the map.
function addMarker(location: google.maps.LatLngLiteral, map: google.maps.Map) {
  // Add the marker at the clicked location, and add the next-available label
  // from the array of alphabetical characters.
  new google.maps.Marker({
    position: location,
    label: labels[labelIndex++ % labels.length],
    map: map,
  });
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

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

// In the following example, markers appear when the user clicks on the map.
// Each marker is labeled with a single alphabetical character.
const labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let labelIndex = 0;

function initMap() {
  const bangalore = { lat: 12.97, lng: 77.59 };
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 12,
    center: bangalore,
  });

  // This event listener calls addMarker() when the map is clicked.
  google.maps.event.addListener(map, "click", (event) => {
    addMarker(event.latLng, map);
  });
  // Add a marker at the center of the map.
  addMarker(bangalore, map);
}

// Adds a marker to the map.
function addMarker(location, map) {
  // Add the marker at the clicked location, and add the next-available label
  // from the array of alphabetical characters.
  new google.maps.Marker({
    position: location,
    label: labels[labelIndex++ % labels.length],
    map: map,
  });
}

window.initMap = initMap;
উদাহরণ দেখুন

নমুনা চেষ্টা করুন

জটিল আইকন

আপনি ক্লিকযোগ্য অঞ্চলগুলি নির্দেশ করতে জটিল আকারগুলি নির্দিষ্ট করতে পারেন এবং অন্যান্য ওভারলেগুলির (তাদের "স্ট্যাক অর্ডার") এর সাথে কীভাবে আইকনগুলি প্রদর্শিত হবে তা নির্দিষ্ট করতে পারেন। এই পদ্ধতিতে নির্দিষ্ট করা আইকনগুলিকে তাদের icon বৈশিষ্ট্যগুলি Icon টাইপের একটি বস্তুতে সেট করা উচিত।

Icon অবজেক্ট একটি ইমেজ সংজ্ঞায়িত করে। তারা আইকনের size , আইকনের origin (যদি আপনি যে চিত্রটি চান তা একটি স্প্রাইটের একটি বড় চিত্রের অংশ হয়, উদাহরণস্বরূপ) এবং আইকনের হটস্পটটি কোথায় অবস্থিত হওয়া উচিত তাও anchor (যার উপর ভিত্তি করে উৎপত্তি)।

আপনি যদি একটি কাস্টম মার্কার সহ একটি লেবেল ব্যবহার করেন তবে আপনি Icon অবজেক্টে labelOrigin বৈশিষ্ট্য সহ লেবেলটি স্থাপন করতে পারেন।

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

// The following example creates complex markers to indicate beaches near
// Sydney, NSW, Australia. Note that the anchor is set to (0,32) to correspond
// to the base of the flagpole.

function initMap(): void {
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 10,
      center: { lat: -33.9, lng: 151.2 },
    }
  );

  setMarkers(map);
}

// Data for the markers consisting of a name, a LatLng and a zIndex for the
// order in which these markers should display on top of each other.
const beaches: [string, number, number, number][] = [
  ["Bondi Beach", -33.890542, 151.274856, 4],
  ["Coogee Beach", -33.923036, 151.259052, 5],
  ["Cronulla Beach", -34.028249, 151.157507, 3],
  ["Manly Beach", -33.80010128657071, 151.28747820854187, 2],
  ["Maroubra Beach", -33.950198, 151.259302, 1],
];

function setMarkers(map: google.maps.Map) {
  // Adds markers to the map.

  // Marker sizes are expressed as a Size of X,Y where the origin of the image
  // (0,0) is located in the top left of the image.

  // Origins, anchor positions and coordinates of the marker increase in the X
  // direction to the right and in the Y direction down.
  const image = {
    url: "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png",
    // This marker is 20 pixels wide by 32 pixels high.
    size: new google.maps.Size(20, 32),
    // The origin for this image is (0, 0).
    origin: new google.maps.Point(0, 0),
    // The anchor for this image is the base of the flagpole at (0, 32).
    anchor: new google.maps.Point(0, 32),
  };
  // Shapes define the clickable region of the icon. The type defines an HTML
  // <area> element 'poly' which traces out a polygon as a series of X,Y points.
  // The final coordinate closes the poly by connecting to the first coordinate.
  const shape = {
    coords: [1, 1, 1, 20, 18, 20, 18, 1],
    type: "poly",
  };

  for (let i = 0; i < beaches.length; i++) {
    const beach = beaches[i];

    new google.maps.Marker({
      position: { lat: beach[1], lng: beach[2] },
      map,
      icon: image,
      shape: shape,
      title: beach[0],
      zIndex: beach[3],
    });
  }
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

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

// The following example creates complex markers to indicate beaches near
// Sydney, NSW, Australia. Note that the anchor is set to (0,32) to correspond
// to the base of the flagpole.
function initMap() {
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 10,
    center: { lat: -33.9, lng: 151.2 },
  });

  setMarkers(map);
}

// Data for the markers consisting of a name, a LatLng and a zIndex for the
// order in which these markers should display on top of each other.
const beaches = [
  ["Bondi Beach", -33.890542, 151.274856, 4],
  ["Coogee Beach", -33.923036, 151.259052, 5],
  ["Cronulla Beach", -34.028249, 151.157507, 3],
  ["Manly Beach", -33.80010128657071, 151.28747820854187, 2],
  ["Maroubra Beach", -33.950198, 151.259302, 1],
];

function setMarkers(map) {
  // Adds markers to the map.
  // Marker sizes are expressed as a Size of X,Y where the origin of the image
  // (0,0) is located in the top left of the image.
  // Origins, anchor positions and coordinates of the marker increase in the X
  // direction to the right and in the Y direction down.
  const image = {
    url: "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png",
    // This marker is 20 pixels wide by 32 pixels high.
    size: new google.maps.Size(20, 32),
    // The origin for this image is (0, 0).
    origin: new google.maps.Point(0, 0),
    // The anchor for this image is the base of the flagpole at (0, 32).
    anchor: new google.maps.Point(0, 32),
  };
  // Shapes define the clickable region of the icon. The type defines an HTML
  // <area> element 'poly' which traces out a polygon as a series of X,Y points.
  // The final coordinate closes the poly by connecting to the first coordinate.
  const shape = {
    coords: [1, 1, 1, 20, 18, 20, 18, 1],
    type: "poly",
  };

  for (let i = 0; i < beaches.length; i++) {
    const beach = beaches[i];

    new google.maps.Marker({
      position: { lat: beach[1], lng: beach[2] },
      map,
      icon: image,
      shape: shape,
      title: beach[0],
      zIndex: beach[3],
    });
  }
}

window.initMap = initMap;
উদাহরণ দেখুন

নমুনা চেষ্টা করুন

MarkerImage অবজেক্টকে টাইপ Icon রূপান্তর করা হচ্ছে

Maps JavaScript API এর 3.10 সংস্করণ পর্যন্ত, জটিল আইকনগুলিকে MarkerImage অবজেক্ট হিসাবে সংজ্ঞায়িত করা হয়েছিল। Icon অবজেক্ট আক্ষরিক সংস্করণ 3.10 এ যোগ করা হয়েছিল, এবং সংস্করণ 3.11 থেকে MarkerImage প্রতিস্থাপন করে। Icon অবজেক্ট লিটারালগুলি একই প্যারামিটারগুলিকে সমর্থন করে MarkerImage এর মতো, যা আপনাকে সহজেই একটি MarkerImage একটি Icon রূপান্তর করার অনুমতি দেয় কনস্ট্রাক্টরকে সরিয়ে, পূর্ববর্তী প্যারামিটারগুলি {} এর মধ্যে মোড়ানো, এবং প্রতিটি প্যারামিটারের নাম যোগ করে৷ উদাহরণ স্বরূপ:

var image = new google.maps.MarkerImage(
    place.icon,
    new google.maps.Size(71, 71),
    new google.maps.Point(0, 0),
    new google.maps.Point(17, 34),
    new google.maps.Size(25, 25));

becomes

var image = {
  url: place.icon,
  size: new google.maps.Size(71, 71),
  origin: new google.maps.Point(0, 0),
  anchor: new google.maps.Point(17, 34),
  scaledSize: new google.maps.Size(25, 25)
};

Optimize markers

Optimization enhances performance by rendering many markers as a single static element. This is useful in cases where a large number of markers is required. By default, the Maps JavaScript API will decide whether a marker will be optimized. When there is a large number of markers, the Maps JavaScript API will attempt to render markers with optimization. Not all Markers can be optimized; in some situations, the Maps JavaScript API may need to render Markers without optimization. Disable optimized rendering for animated GIFs or PNGs, or when each marker must be rendered as a separate DOM element. The following example shows creating an optimized marker:

var marker = new google.maps.Marker({
    position: myLatlng,
    title:"Hello World!",
    optimized: true 
});

একটি মার্কার অ্যাক্সেসযোগ্য করুন

আপনি একটি ক্লিক লিসেনার ইভেন্ট যোগ করে এবং false optimized সেট করে একটি মার্কারকে অ্যাক্সেসযোগ্য করে তুলতে পারেন। ক্লিক লিসেনারের কারণে মার্কারের বোতামের শব্দার্থবিদ্যা রয়েছে, যা কীবোর্ড নেভিগেশন, স্ক্রিন রিডার ইত্যাদি ব্যবহার করে অ্যাক্সেস করা যেতে পারে। একটি চিহ্নিতকারীর জন্য অ্যাক্সেসযোগ্য পাঠ্য উপস্থাপন করতে title বিকল্পটি ব্যবহার করুন।

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

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

// The following example creates five accessible and
// focusable markers.

function initMap(): void {
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 12,
      center: { lat: 34.84555, lng: -111.8035 },
    }
  );

  // Set LatLng and title text for the markers. The first marker (Boynton Pass)
  // receives the initial focus when tab is pressed. Use arrow keys to
  // move between markers; press tab again to cycle through the map controls.
  const tourStops: [google.maps.LatLngLiteral, string][] = [
    [{ lat: 34.8791806, lng: -111.8265049 }, "Boynton Pass"],
    [{ lat: 34.8559195, lng: -111.7988186 }, "Airport Mesa"],
    [{ lat: 34.832149, lng: -111.7695277 }, "Chapel of the Holy Cross"],
    [{ lat: 34.823736, lng: -111.8001857 }, "Red Rock Crossing"],
    [{ lat: 34.800326, lng: -111.7665047 }, "Bell Rock"],
  ];

  // Create an info window to share between markers.
  const infoWindow = new google.maps.InfoWindow();

  // Create the markers.
  tourStops.forEach(([position, title], i) => {
    const marker = new google.maps.Marker({
      position,
      map,
      title: `${i + 1}. ${title}`,
      label: `${i + 1}`,
      optimized: false,
    });

    // Add a click listener for each marker, and set up the info window.
    marker.addListener("click", () => {
      infoWindow.close();
      infoWindow.setContent(marker.getTitle());
      infoWindow.open(marker.getMap(), marker);
    });
  });
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

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

// The following example creates five accessible and
// focusable markers.
function initMap() {
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 12,
    center: { lat: 34.84555, lng: -111.8035 },
  });
  // Set LatLng and title text for the markers. The first marker (Boynton Pass)
  // receives the initial focus when tab is pressed. Use arrow keys to
  // move between markers; press tab again to cycle through the map controls.
  const tourStops = [
    [{ lat: 34.8791806, lng: -111.8265049 }, "Boynton Pass"],
    [{ lat: 34.8559195, lng: -111.7988186 }, "Airport Mesa"],
    [{ lat: 34.832149, lng: -111.7695277 }, "Chapel of the Holy Cross"],
    [{ lat: 34.823736, lng: -111.8001857 }, "Red Rock Crossing"],
    [{ lat: 34.800326, lng: -111.7665047 }, "Bell Rock"],
  ];
  // Create an info window to share between markers.
  const infoWindow = new google.maps.InfoWindow();

  // Create the markers.
  tourStops.forEach(([position, title], i) => {
    const marker = new google.maps.Marker({
      position,
      map,
      title: `${i + 1}. ${title}`,
      label: `${i + 1}`,
      optimized: false,
    });

    // Add a click listener for each marker, and set up the info window.
    marker.addListener("click", () => {
      infoWindow.close();
      infoWindow.setContent(marker.getTitle());
      infoWindow.open(marker.getMap(), marker);
    });
  });
}

window.initMap = initMap;
উদাহরণ দেখুন

নমুনা চেষ্টা করুন

একটি মার্কার অ্যানিমেট

আপনি মার্কারগুলিকে অ্যানিমেট করতে পারেন যাতে তারা বিভিন্ন পরিস্থিতিতে গতিশীল আন্দোলন প্রদর্শন করে। একটি মার্কার যেভাবে অ্যানিমেটেড হয় তা নির্দিষ্ট করতে, google.maps.Animation টাইপের মার্কারের animation বৈশিষ্ট্য ব্যবহার করুন। নিম্নলিখিত Animation মান সমর্থিত:

  • DROP নির্দেশ করে যে মার্কারটি মানচিত্রের শীর্ষ থেকে তার চূড়ান্ত অবস্থানে নেমে যাওয়া উচিত যখন মানচিত্রে প্রথম স্থাপন করা হয়। মার্কারটি বিশ্রামে এলে অ্যানিমেশন বন্ধ হয়ে যাবে এবং animation null ফিরে যাবে। এই ধরনের অ্যানিমেশন সাধারণত Marker তৈরির সময় নির্দিষ্ট করা হয়।
  • BOUNCE নির্দেশ করে যে মার্কারটি জায়গায় বাউন্স করা উচিত। একটি বাউন্সিং মার্কার বাউন্সিং চালিয়ে যাবে যতক্ষণ না তার animation সম্পত্তি স্পষ্টভাবে null সেট করা হয়।

আপনি Marker অবজেক্টে setAnimation() কল করে একটি বিদ্যমান মার্কারে একটি অ্যানিমেশন শুরু করতে পারেন।

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

// The following example creates a marker in Stockholm, Sweden using a DROP
// animation. Clicking on the marker will toggle the animation between a BOUNCE
// animation and no animation.

let marker: google.maps.Marker;

function initMap(): void {
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 13,
      center: { lat: 59.325, lng: 18.07 },
    }
  );

  marker = new google.maps.Marker({
    map,
    draggable: true,
    animation: google.maps.Animation.DROP,
    position: { lat: 59.327, lng: 18.067 },
  });
  marker.addListener("click", toggleBounce);
}

function toggleBounce() {
  if (marker.getAnimation() !== null) {
    marker.setAnimation(null);
  } else {
    marker.setAnimation(google.maps.Animation.BOUNCE);
  }
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

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

// The following example creates a marker in Stockholm, Sweden using a DROP
// animation. Clicking on the marker will toggle the animation between a BOUNCE
// animation and no animation.
let marker;

function initMap() {
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 13,
    center: { lat: 59.325, lng: 18.07 },
  });

  marker = new google.maps.Marker({
    map,
    draggable: true,
    animation: google.maps.Animation.DROP,
    position: { lat: 59.327, lng: 18.067 },
  });
  marker.addListener("click", toggleBounce);
}

function toggleBounce() {
  if (marker.getAnimation() !== null) {
    marker.setAnimation(null);
  } else {
    marker.setAnimation(google.maps.Animation.BOUNCE);
  }
}

window.initMap = initMap;
উদাহরণ দেখুন

নমুনা চেষ্টা করুন

আপনার যদি অনেকগুলি চিহ্নিতকারী থাকে, আপনি হয়ত সেগুলিকে একবারে মানচিত্রে ফেলে দিতে চাইবেন না৷ আপনি নীচে দেখানো মত একটি প্যাটার্ন ব্যবহার করে আপনার মার্কার অ্যানিমেশন স্পেস করতে setTimeout() ব্যবহার করতে পারেন:

function drop() {
  for (var i =0; i < markerArray .length; i++) {
    setTimeout(function() {
      addMarkerMethod ();
    }, i * 200);
  }
}

উদাহরণ দেখুন

একটি মার্কার টেনে আনা যায়

ব্যবহারকারীদের মানচিত্রের একটি ভিন্ন অবস্থানে একটি মার্কার টেনে আনতে অনুমতি দিতে, মার্কার বিকল্পগুলিতে draggable true করুন।

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
  zoom: 4,
  center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);

// Place a draggable marker on the map
var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    draggable:true,
    title:"Drag me!"
});

আরও মার্কার কাস্টমাইজেশন

একটি সম্পূর্ণ-কাস্টমাইজড মার্কারের জন্য, কাস্টমাইজড পপআপ উদাহরণ দেখুন।

মার্কার ক্লাসের আরও এক্সটেনশন, মার্কার ক্লাস্টারিং এবং পরিচালনা এবং ওভারলে কাস্টমাইজেশনের জন্য, ওপেন সোর্স লাইব্রেরি দেখুন।