<!--
@license
Copyright 2019 Google LLC. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
-->
<!-- [START maps_advanced_markers_simple] -->
<html>
<head>
<title>Default Advanced Marker</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="map"></div>
<!-- prettier-ignore -->
<script>(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,n)=>r.add(f)&&u().then(()=>d[l](f,n))})
({key: "YOUR_API_KEY", v: "beta"});</script>
</body>
</html>
<!-- [END maps_advanced_markers_simple] -->
let map;
async function initMap() {
// instantiate the libraries
const {Marker} = await google.maps.importLibrary("marker");
const { event } = await google.maps.importLibrary("core");
const { Map } = await google.maps.importLibrary("maps");
// instantiate the map
map = new Map(document.getElementById("map"), {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
});
// instantiate the marker
marker = new Marker({
map,
draggable: true,
position: {lat: -34.397, lng: 150.644},
})
// This adds a click event listener to your marker
let markerListenerEvent = event.addListener(marker, "click", function() {
alert("you have clicked the marker!")
});
// this will show in the console that
// the marker now have a click event listener.
console.log("clickable marker: ");
console.log(marker.__e3_.click[64].So);
// this will return "true"
// clicking on the map will then remove the listener you put
// on the marker
let mapListenerEvent = event.addListener(map, "click", function() {
alert("You have now removed the marker event listener!")
// This is the the method that removes the listener for marker above
event.removeListener(markerListenerEvent);
// this will show in the console that
// the marker now don't have a click event listener
// since the "click" object will now be empty.
console.log("not clickable marker: ");
console.log(marker.__e3_.click);
// this will return an empty object
})
}
initMap();
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |