我正在使用來自 mapbox 的地圖地理編碼器,它在 mapbox 文檔的示例中使用。但是,我無法獲取返回的值。我需要用戶選擇的地址,如果可能的話,在 gps 經度/緯度字符串中。這是我的代碼:<div id="geocoder" name="geocoder" class="form-control txt-field"></div><script> mapboxgl.accessToken = 'MY TOKEN API'; var geocoder = new MapboxGeocoder({ accessToken: mapboxgl.accessToken, placeholder: 'point de depart' }); document.getElementById('geocoder').appendChild(geocoder.onAdd()); geocoder.on('results', function (results) { document.getElementById('mapr').value = (results); })</script>
1 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
每當更新建議列表時都會調用該事件,以獲取用戶選擇的results
結果,然后您應該收聽該事件。result
gecoder.on('result',?e?=>?{ ??console.log(e.result) })
- 1 回答
- 0 關注
- 130 瀏覽
添加回答
舉報
0/150
提交
取消