如何返回Googleapi搜索结果的距离



这是我在需要的距离内获取所有项目的方式:

query_string = 'distance(LocationCoord, geopoint(35.2, 40.5)) < 1000'
query_options = search.QueryOptions(
    returned_fields=['ID', 'GUID', 'LocationCoord', '**distance()**']
)
query = search.Query(query_string=query_string, options=query_options)
res = index.search(query)

我实际上将如何返回搜索结果中的距离?

为此,您可以添加字段表达:

query_string = 'distance(LocationCoord, geopoint(35.2, 40.5)) < 1000'
expression = search.FieldExpression(name='distance', expression='distance(LocationCoord, geopoint(35.2, 40.5))')
query_options = search.QueryOptions(
    returned_fields=['ID', 'GUID', 'LocationCoord']
    returned_expressions=[expression],
)
query = search.Query(query_string=query_string, options=query_options)
res = index.search(query)

相关内容

  • 没有找到相关文章