【问题标题】:BadValueError: Expected GeoPtBadValueError:预期的 GeoPt
【发布时间】:2013-09-16 20:35:47
【问题描述】:

我正在尝试将值从 html 表单传递到 gae 数据存储并收到以下错误:

“BadValueError:预期的 GeoPt,得到 (51.123, -0.123)”

先道歉,但我是新手,所以可能会做错事,但非常感谢一些关于最佳方式的建议。

提前致谢。

【问题讨论】:

    标签: google-app-engine geolocation google-cloud-datastore geocoding


    【解决方案1】:

    看起来您正在尝试将元组分配给属性而不是 geopt。

    您的代码会这样做:

    entity.some_geo_property = (51.123, -0.123)
    

    需要这样做的地方:

    from google.appengine.ext import ndb
    
    entity.some_geo_property = ndb.GeoPt(51.123, -0.123)
    

    或者使用元组:

    entity.some_geo_property = ndb.GeoPt(*value)
    

    如果没有看到您的确切代码,就很难提供完整的解决方案。如果您提供代码,我会尝试更新我的答案。

    【讨论】:

    • 谢谢,非常感谢
    【解决方案2】:

    我从未使用过 GeoPt 属性,但我认为您传递了一个包含两个浮点数的元组。

    首先将值传递给 ndb.GeoPt() 并将返回值存储在 NDB 中。示例:

    location = ndb.GeoPt(51.123, -0.123)
    

    如果你使用 HRD 的 DB API 而不是 NDB API,使用 db.GeoPt() 基本相同。

    【讨论】:

    • 谢谢,非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2020-09-20
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多