使用 GAE 端点从浮点数转换后的双精度值无效

Invalid double value after cast from float with GAE endpoints

我正在使用来自 google 云的端点 API 并发送双精度值,它们是从 Android 中的浮点数转换而来的。大多数情况下这都很好,但我注意到使用少量设备时会出现以下错误:

400 次错误请求

{
    "code": 400,
    "errors": [{
        "domain": "global",
        "location": "longitude",
        "locationType": "parameter",
        "message": "Invalid double value: '116.31765747070313'.",
        "reason": "invalidParameter"
    }],
    "message": "Invalid double value: '116.31765747070313'."
}

这是 android 端的代码:

void callEndpoints(final int level, final float latitude, final float longitude) {
    try {
        API.GetPlacesFromLocationV2 remoteData = cbAPI.getPlacesFromLocationV2();

        remoteData.setLatitude((double)latitude);
        remoteData.setLongitude((double)longitude);
        remoteData.setLevel((long) level);

        Result res = remoteData.execute();

        //Do stuff with res
    } catch (IOException e) {
        //print error
    }
}

这是 python 服务器端代码。

PLACES_LOCATION_SEARCH_V2_CONTAINER = endpoints.ResourceContainer(
   message_types.VoidMessage,
   level=messages.IntegerField(1),
   longitude=messages.FloatField(2),
   latitude=messages.FloatField(3)
)

def getCellIdx(level, lon, lat):
   scale = pow(2, level)
   cellWidth = FULL_WIDTH / scale
   cellHeight = FULL_HEIGHT / scale

   wIdx = int((lon + 180.0) / cellWidth)
   hIdx = int((lat + 90.0) / cellHeight)

   return level * 100000000 + hIdx * 10000 + wIdx

@endpoints.method(PLACES_LOCATION_SEARCH_V2_CONTAINER, 
   DataCollection, 
   path="getPlacesFromLocation_v2", http_method='GET', 
   name="getPlacesFromLocation_v2")
def getPlacesFromLocation_v2(self, request):
  cellIdx = placesGridSearch.getCellIdx(request.level,request.longitude,request.latitude)
  #Do stuff with cellIdx, includes datastore access and memcache usage
  return DataCollection(cellIdx)

感谢您的帮助。

编辑: 一些附加信息,如果我通过 API 资源管理器 运行 它在云上使用相同的经度值,我会得到相同的错误,但如果我 运行 它在我的本地开发服务器上则不会。 看起来端点函数从未被调用过(没有日志)但是有 /_ah/spi/BackendService.logMessages 日志描述了完全相同的错误。

Upgrade to Endpoints Frameworks v2。不会有这个问题。