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

标签 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)

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

最佳答案

为此,您可以添加 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)

关于python - 如何返回GoogleAPI搜索结果的距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30145503/

相关文章:

python - flask 错误 : typeerror run() got an unexpected keyword argument 'host'

java - 在appengine中追溯分配关键范围

android - 即使我们只使用只读模式,我是否必须在 4 月 27 日之前更新 Google Fitness SDK v20?

python - 将大文本文件(约 50GB)拆分为多个文件

python - Pyplot 的刻度值可以被自动间隔整除吗?

java - AppEngine 网站中的在线用户

python - 如何在 Google App Engine 中清理 python 中的 html blob 上传?

java - SMS Retriever API 中发布的 APK 上的 HASH 字符串 key

google-api - 如何解决 403 错误 : User rate limit exceeded in Google Drive API?

python - 添加 alpha channel 时图像不会改变