我使用places.js库进行自动完成,但也希望将其用于逆向地理编码。根据https://community.algolia.com/places/examples.html#reverse-geocoding的说法,这应该是可能的--自动完成很好,但不是反向调用。代码摘录:
places.configure({
hitsPerPage: 1,
aroundLatLng: position.coords.latitude + ',' + position.coords.longitude,
});
places.reverse({
//aroundLatLng: position.coords.latitude + ',' + position.coords.longitude,
//hitsPerPage: 1
}).then(function(response){
var hits = response.hits;
var suggestion = hits[0];
if (suggestion && (suggestion.locale_names || suggestion.city)) {
address_input.value = suggestion.locale_names.default[0] || suggestion.city.default[0];
}
});这会触发对正确端点的调用,但是aroundLatLng丢失了错误。我已经确认了数据在那里--而且hitsPerPage仍然是默认的5。正如您从注释行中看到的那样,我尝试将这些选项直接传递给reverse调用,并使用configure。
有人能告诉我使用places.js库进行反向调用的正确方法吗?
谢谢。
发布于 2019-05-16 17:43:22
因此,问题在于阿尔戈利亚提供了两种方法来调用逆向地理编码,但实际上只记录了其中一种。
algolia的反向地理编码示例使用来自algolia客户端库的places实现,该库允许您执行以下操作:
const places = algoliasearch.initPlaces('appId', 'apiKey');
places.reverse({ aroundLatLng: 'lat,lng', hitsPerPage: 5 }).then(callback);在reverse库中还有另一个可用的places.js方法,这个方法的参数略有不同:
const placesAutocomplete = places({ appId: '', apiKey: '', container: inputEl });
places.reverse('lat,lng', { hitsPerPage: 5 });注意如何将纬度/经度对作为第一个参数,然后查询params作为第二个对象参数。
https://stackoverflow.com/questions/56116535
复制相似问题