VM701:1 Uncaught SyntaxError: Identifier 'defaultLocations' has already been declared

Viewed 13

I have a problem when a form create is creating a form using a map, the map I use is mapbox, I declare the defaultLocations variable using i frame, I have no problem when it opens the first time, but I have a problem when it opens the second time and so on. Thank you very much, please help when someone encounters the problem I'm experiencing

here's the code

<script>
        const defaultLocations = [106.80802690000831,-6.408099825683934]
        const defaultLocation = [106.80802690000831,-6.408099825683934]
        mapboxgl.accessToken = 'pk.eyJ1IjoibWNmZXJuaXphYSIsImEiOiJjbDdvbHptOGsweXN4M29uYnZhN2VidzB4In0.GSeO9H-H3w93H7p9VDuUUQ';
        const coordinates = document.getElementById('coordinates');
        var map = new mapboxgl.Map({
            container: 'map',
            center: defaultLocations,
            zoom: 10,
            style: 'mapbox://styles/mapbox/streets-v11'
        });

        // const marker1 = new mapboxgl.Marker()
        //     .addTo(map);
        map.on('idle',function(){
            map.resize()
        })
        map.addControl(new mapboxgl.NavigationControl());
        map.on('click', (e) => {
            const longtitude = e.lngLat.lng
            const lattitude = e.lngLat.lat
            console.log(longtitude,lattitude)
            $('#lng').val(longtitude)
            $('#lat').val(lattitude)
        })
        const marker = new mapboxgl.Marker({
            draggable: true
        })
            .setLngLat()
            .addTo(map);

</script>

here's the error with maps that don't appear the second time enter image description here

0 Answers
Related