mapbox-gl-geocoder icon indicating copy to clipboard operation
mapbox-gl-geocoder copied to clipboard

GeoCoder query function returns undefined style error

Open CharlesBilbo opened this issue 5 years ago • 1 comments

whenever using the query function on the geoCoder instance an error of Undifined is returned on the object style

Screen Shot 2020-12-16 at 10 20 24 PM

        mapboxgl.accessToken = this.mapboxToken;
        this.map = new mapboxgl.Map({
            container: 'map-element',
            style: 'mapbox://styles/mapbox/light-v10',
            center: [-103.59179687498357, 40.66995747013945],
            zoom: 3
        })
        let geocoder = new MapboxGeocoder({
            accessToken: mapboxgl.accessToken,
            mapboxgl: mapboxgl,
            marker: false,

        })

        geocoder.query('new york')`

CharlesBilbo avatar Dec 17 '20 04:12 CharlesBilbo

same issue

After 4 hours searching, I found the solution You need to add geocoder to DOM/HTML element Ex:

          <div id='geocoder-container' class="d-none"></div>



            var geocoder = new MapboxGeocoder({
                accessToken: mapboxgl.accessToken,
                mapboxgl: mapboxgl,
                marker: false,
                flyTo: false
            });
            geocoder.addTo('#geocoder-container')
            geocoder.query('new york')
            geocoder.on('result', function (result) {
                console.log(result)
            })

tonviet712 avatar Feb 22 '21 03:02 tonviet712