Last active
March 31, 2022 14:16
-
-
Save AtakanATC/acf845b71ad4851dedd447b15b6e1b4c to your computer and use it in GitHub Desktop.
google maps multi marker with js and twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="maps" style="height:400px; width:100%"></div> | |
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script> | |
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap&v=weekly" async></script> | |
<script> | |
function initMap() { | |
{% set defaultCenter = iletisim[0].cevaplar.konum.cevap|split(',') %} | |
{% set defaultLat = defaultCenter[0] %} | |
{% set defaultLng = defaultCenter[1] %} | |
const map = new google.maps.Map(document.getElementById("maps"), { | |
zoom: 5, | |
center: { lat:{{defaultLat}}, lng:{{defaultLng}} }, | |
}); | |
{% for item in iletisim %} | |
{% set konum = item.cevaplar.konum.cevap|split(',') %} | |
{% set lat = konum[0] %} | |
{% set lng = konum[1] %} | |
new google.maps.Marker({ | |
position: { lat:{{lat}}, lng:{{lng}} }, | |
map, | |
title: "{{item.ad}}", | |
}); | |
{% endfor %} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment