如何返回GoogleAPI搜索结果的距离?

时间:2015-05-09 22:03:23

标签: python google-app-engine google-api

以下是我如何获得所需距离的所有项目:

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)

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

1 个答案:

答案 0 :(得分:1)

为此,您可以添加FieldExpression

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)