A Pen by Raymond Camden on CodePen.
Created
June 22, 2024 12:39
-
-
Save neisdev/2e363269088bae8a3ccbd5559878c63d to your computer and use it in GitHub Desktop.
Alpine + Google Maps 1
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
<script src="https://unpkg.com/[email protected]/dist/cdn.min.js" defer></script> | |
<div x-data="app"> | |
<template x-for="store in stores"> | |
<p> | |
Store location: <span x-text="store.lat"></span>,<span x-text="store.lng"></span><br/> | |
<img :src="getImageUrl(store.lat,store.lng)"> | |
</p> | |
</template> | |
</div> |
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
const MAP_KEY = 'AIzaSyC3hC35ehz1oAfUll7q7qzUlPa27Gz5g5g'; | |
document.addEventListener('alpine:init', () => { | |
Alpine.data('app', () => ({ | |
stores:getStores(), | |
getImageUrl(lat,lng) { | |
return `https://maps.googleapis.com/maps/api/staticmap?center=${lat},${lng}&zoom=15&size=400x400&maptype=roadmap&markers=color:blue%7C${lat},${lng}&key=${MAP_KEY}` | |
} | |
})) | |
}); | |
/* | |
imagine this was an API call.. | |
*/ | |
function getStores() { | |
return [ | |
{ | |
"lat": 30.175776, | |
"lng": -92.077008, | |
"allday":true | |
}, | |
{ | |
"lat": 30.173529, | |
"lng": -92.078997, | |
"allday":true | |
}, | |
{ | |
"lat": 30.394324, | |
"lng": -91.086551, | |
"allday":false | |
}, | |
{ | |
"lat": 30.176162, | |
"lng": -93.219241, | |
"allday":false | |
}, | |
{ | |
"lat": 31.269887, | |
"lng": -92.46034, | |
"allday":false | |
}, | |
{ | |
"lat": 29.61629, | |
"lng": -90.757389, | |
"allday":false | |
}, | |
{ | |
"lat": 30.486217, | |
"lng": -90.45677, | |
"allday":false | |
} | |
] | |
} |
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
[x-cloak] { display: none !important; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment