I try to use imported vars from a js
file into my code but I can't get it to work the excepted way.
location_var.js
var location = {
place: "Bogotá",
lat: "4.710988599999999",
lng: "-74.072092"
};
export { location };
index.html
<script type="module">
import { location } from './location_var.js'
console.log(location.lat) // this will be displayed
</script>
but if I put a <script>
tag below, I can't use my variables back.
<body>
<!--The div element for the map -->
<div id="map"></div>
<script>
function initMap() {
var place = { lat: location.lat, lng: location.lng }; // this doesn't work - console says the vars are undefined for some reasons
var map = new google.maps.Map(
document.getElementById('map'), { zoom: 4, center: place });
var marker = new google.maps.Marker({ position: place, map: map });
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=initMap">
</script>
</body>
Any ideas why I can't call it back there?
Aucun commentaire:
Enregistrer un commentaire