सुविधा के बारे में जानकारी
मार्कर, मैप पर किसी जगह की पहचान करता है. डिफ़ॉल्ट रूप से, मार्कर
सामान्य इमेज का इस्तेमाल करता है. मार्कर, कस्टम इमेज दिखा सकते हैं. इस स्थिति में, उन्हें आम तौर पर "आइकॉन" कहा जाता है. मार्कर और आइकॉन,
Marker
टाइप के ऑब्जेक्ट हैं. आप मार्कर के कंस्ट्रक्टर में या मार्कर पर
setIcon()
को कॉल करके कस्टम आइकॉन सेट कर सकते हैं.
मार्कर इमेज को पसंद के मुताबिक बनाने के बारे में ज़्यादा जानें.
बड़े पैमाने पर कहा जाए, तो मार्कर ओवरले का एक प्रकार होते हैं. दूसरी तरह के ओवरले के बारे में जानकारी के लिए, मैप पर ड्रॉइंग करना देखें.
मार्कर इंटरैक्टिव होने के लिए डिज़ाइन किए गए हैं. उदाहरण के लिए, डिफ़ॉल्ट रूप से उन्हें 'click'
इवेंट मिलते हैं. इसलिए, आप कस्टम जानकारी दिखाने वाली जानकारी विंडो में लाने के लिए, इवेंट लिसनर जोड़ सकते हैं. draggable
की प्रॉपर्टी को
true
पर सेट करके, उपयोगकर्ताओं को
मैप पर कोई मार्कर मूव करने की अनुमति दी जा सकती है. खींचे जाने वाले मार्कर के बारे में ज़्यादा जानकारी के लिए, नीचे देखें.
कोई मार्कर जोड़ें
google.maps.Marker
कंस्ट्रक्टर, मार्कर की शुरुआती प्रॉपर्टी के बारे में बताने वाला एक ही Marker options
ऑब्जेक्ट
लिटरल लेता है.
ये फ़ील्ड खास तौर पर अहम होते हैं और आम तौर पर, मार्कर बनाते समय सेट किए जाते हैं:
-
position
(ज़रूरी है) मार्कर की शुरुआती जगह की पहचान करने वालाLatLng
दिखाता है.LatLng
को इस्तेमाल करने का एक तरीका, जियोकोडिंग सेवा का इस्तेमाल करना है. -
map
(ज़रूरी नहीं) वहMap
बताता है जिस पर मार्कर लगाना है. अगर आप मार्कर बनाने के लिए मैप तय नहीं करते हैं, तो मार्कर बनाया जाता है, लेकिन मैप से जुड़ा (या दिखाया) नहीं जाता. मार्कर को बाद में जोड़ा जा सकता है. इसके लिए, आपको मार्कर केsetMap()
तरीके को कॉल करना होगा.
नीचे दिए गए उदाहरण में, उलुरू के मैप में ऑस्ट्रेलिया के केंद्र में एक आसान मार्कर जोड़ा गया है:
TypeScript
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;
JavaScript
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.
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.
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;
JavaScript
// 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
प्रॉपर्टी का होना ज़रूरी है. मार्कर (और पॉलीलाइन) के लिए
वेक्टर-आधारित आइकॉन बनाने के लिए चिह्नों का इस्तेमाल करने
के बारे में ज़्यादा जानें.
TypeScript
// 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;
JavaScript
// 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()
को कॉल किया जा सकता है.
जब उपयोगकर्ता मैप पर क्लिक करता है, तो इस उदाहरण में लेबल किए गए मार्कर दिखते हैं:
TypeScript
// 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;
JavaScript
// 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
प्रॉपर्टी के साथ रखा जा सकता है.
TypeScript
// 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;
JavaScript
// 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 एपीआई के वर्शन 3.10 तक, कॉम्प्लेक्स आइकॉन को MarkerImage
ऑब्जेक्ट के तौर पर दिखाया जाता था. Icon
ऑब्जेक्ट लिटरल को वर्शन 3.10 में जोड़ा गया था और यह MarkerImage
को वर्शन 3.11 से बदल देता है.
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 });
मार्कर को ऐक्सेस करने लायक बनाना
क्लिक लिसनर इवेंट को जोड़कर और
optimized
को false
पर सेट करके, मार्कर को ऐक्सेस किया जा सकता है. क्लिक लिसनर की वजह से, मार्कर में बटन सिमैंटिक होता है. इसे कीबोर्ड नेविगेशन, स्क्रीन रीडर वगैरह की मदद से ऐक्सेस किया जा सकता है. मार्कर के लिए ऐक्सेस किया जा सकने वाला टेक्स्ट प्रज़ेंट करने के लिए,
title
विकल्प का इस्तेमाल करें.
नीचे दिए गए उदाहरण में, टैब दबाने पर, पहले मार्कर को फ़ोकस मिलता है. इसके बाद, मार्कर के बीच इधर-उधर जाने के लिए, ऐरो बटन का इस्तेमाल किया जा सकता है. बाकी मैप कंट्रोल से आगे बढ़ने के लिए, टैब को फिर से दबाएं. अगर मार्कर की जानकारी विंडो है, तो मार्कर पर क्लिक करके उसे खोला जा सकता है. इसके अलावा, मार्कर को चुनने पर, Enter बटन या Space बार को दबाकर भी इसे खोला जा सकता है. जानकारी देने वाली विंडो बंद होने पर, फ़ोकस उससे जुड़े मार्कर पर वापस आ जाएगा.
TypeScript
// 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;
JavaScript
// 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
से यह पता चलता है कि मैप पर पहली बार रखे जाने पर, मार्कर को मैप के सबसे ऊपर वाली आखिरी जगह पर छोड़ना चाहिए. मार्कर को आराम देते ही ऐनिमेशन बंद हो जाएगा औरnull
कोanimation
वापस लाया जाएगा. आम तौर पर, इस तरह का ऐनिमेशनMarker
बनाने के दौरान बताया जाता है. -
BOUNCE
यह बताता है कि मार्कर को सही जगह पर बाउंस होना चाहिए. बाउंस होने वाला मार्कर तब तक बाउंस होता रहेगा, जब तक उसकीanimation
प्रॉपर्टी,null
पर सेट नहीं हो जाती.
आप Marker
ऑब्जेक्ट पर setAnimation()
को कॉल करके, मौजूदा मार्कर पर
ऐनिमेशन शुरू कर सकते हैं.
TypeScript
// 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;
JavaScript
// 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!" });
आगे के मार्कर कस्टमाइज़ेशन
पूरी तरह से पसंद के मुताबिक बनाए गए मार्कर के लिए, कस्टमाइज़ किए गए पॉप-अप का उदाहरण देखें.
मार्कर क्लास के ज़्यादा एक्सटेंशन, मार्कर क्लस्टर बनाने, और ओवरले को पसंद के मुताबिक बनाने के लिए, ओपन सोर्स लाइब्रेरी देखें.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2023-09-18 (UTC) को अपडेट किया गया.