【发布时间】:2019-05-17 01:43:22
【问题描述】:
我正在使用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库进行反向调用的正确方法吗?
谢谢。
【问题讨论】:
-
你确定
position.coords.{latitude|longitude}中有实际数据吗? -
是的 100%。我正在做的事情根本上是错误的,因为当我查看名为的 URL 时,甚至 hitsPerPage 值也没有正确传递
标签: javascript algolia