从Mapbox Geocoder检索数据 [英] Retrieve data from mapbox geocoder

查看:392
本文介绍了从Mapbox Geocoder检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要地图框地理编码自动完成而不需要地图(将带有lat/lng的结果放入另一个请求中)

i only need the mapbox geocoding autocomplete without the map (to put the result with lat/lng in another request)

我设法完全不使用地图而将其单独放置了:

I managed to put it totally alone without the map using this :

<template>
    <div id='geocoder' class='geocoder'></div>
</template>

<script>
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder'
require('../../node_modules/@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css')

mapboxgl.accessToken = '<your access token here>';
var geocoder = new MapboxGeocoder({
    accessToken: mapboxgl.accessToken
    placeholder: 'Rechercher'
});
document.getElementById('geocoder').appendChild(geocoder.onAdd());
</script>

但是现在我想检索数据(特别是lat/lng属性,以便将其保存在组件中并使用它)

But now i would like to retrieve the data (specifically the lat/lng attribute in order to save it in my component and work with it)

我该怎么做?我已经搜索了mapbox文档,但未找到有关此内容的任何信息:/

How can i do that ? i've search through mapbox doc but did not found anything about that :/

提前感谢社区

推荐答案

来自API文档

From the API docs https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#on you can use

geocoder.on('results', function(results) {
   console.log(results);
})

这篇关于从Mapbox Geocoder检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆