首页 文章

从具有GAE endpoints 的float转换后无效的double值

提问于
浏览
0

我正在使用谷歌 Cloud 端的 endpoints 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浏览器运行它与 Cloud 上的经度具有相同的值,我会得到相同的错误,但如果我在本地开发服务器上运行它,则不会 . 它看起来似乎永远不会调用 endpoints 函数(没有日志)但是有一个/_ah/spi/BackendService.logMessages日志描述完全相同的错误 .

1 回答

相关问题