如何使用javascript将LatlngBounds对象传递给nodejs服务器

我想从客户端传递一个LatlngBounds对象到nodejs服务器。

var bounds = map.getBounds(); socket.emit('sendbounds', bounds); 

在服务器上:

  socket.on('sendbounds',function(data){ console.log(data); data.getNorthEast();// undefined method getNorthEast() } 

服务器可以获取客户端发送的数据。 但是我无法使用方法getNorthEast()。

我的解决scheme是创build一个对象LatlngBounds:

 bounds = new google.maps.LatLng(data.Ea.k, data.va.j), new google.maps.LatLng(data.Ea.j, data.va.k)); 

不过这并不推荐,因为我们无法确定键名是否总是'Ea'和'va'。 我注意到有时键名是“Fa”和“wa”,它们是“无证的属性”,它们随着API的发布而变化。

任何解决scheme来解决这个问题?

我也尝试过这种方式,但也遇到同样的问题:不能依赖variables名称。

相反,我把它作为一个string,而不是一个对象传递给服务器: corners = map.getBounds(); var c = corners.toString(); corners = map.getBounds(); var c = corners.toString();

然后使用任何AJAX库将string发送到服务器。 它看起来像这样:

((33.94310833405608, -118.44952616442868), (33.985820303992334, -118.34120783557125))

你将不得不使用正则expression式分开,但至less它是可靠的格式。