Javascript 如何在数据库中无误地保存Google maps v3圆形和矩形覆盖图?

Javascript 如何在数据库中无误地保存Google maps v3圆形和矩形覆盖图?,javascript,json,google-maps-api-3,Javascript,Json,Google Maps Api 3,我使用JSON方法在数据库中保存Google覆盖图。例如,我通过以下代码在数据库中保存了一个圆: var shape_properties; shape_properties.center = array_shapes_object[counter].center; shape_properties.redius = array_shapes_object[counter].radius; shape_properties.type = array_shapes_object[counter]

我使用JSON方法在数据库中保存Google覆盖图。例如,我通过以下代码在数据库中保存了一个圆:

var shape_properties;

shape_properties.center = array_shapes_object[counter].center;
shape_properties.redius = array_shapes_object[counter].radius;
shape_properties.type = array_shapes_object[counter].type;                   
shape_properties.zIndex = array_shapes_object[counter].zIndex;
shape_properties.fillColor = array_shapes_object[counter].get('fillColor');
shape_properties.name = array_shapes_object[counter].name;

array_shapes_string.push(JSON.stringify(shape_properties));
newShape = new google.maps.Circle({
center:new google.maps.LatLng(array_shapes_object[counter].center.d, array_shapes_object[counter].center.e),
radius:array_shapes_object[counter].redius,
zIndex:array_shapes_object[counter].zIndex,
fillColor:array_shapes_object[counter].fillColor,
fillOpacity: 0.15,
strokeColor: '#FF0000',
strokeWeight: 1
});
我有一个名为shape\u properties的变量,我将所有圆属性保存在其中,然后使用
JSON.stringify(shape\u properties)
将其更改为字符串,最后将该字符串保存到数据库中

当我想在地图上画这个圆的时候,我会用类似的东西。我的意思是从数据库中读取这些包含圆圈属性的字符串,然后使用
JSON.parse(array\u shapes\u string[counter])将其更改为object
,最后使用以下代码绘制:

var shape_properties;

shape_properties.center = array_shapes_object[counter].center;
shape_properties.redius = array_shapes_object[counter].radius;
shape_properties.type = array_shapes_object[counter].type;                   
shape_properties.zIndex = array_shapes_object[counter].zIndex;
shape_properties.fillColor = array_shapes_object[counter].get('fillColor');
shape_properties.name = array_shapes_object[counter].name;

array_shapes_string.push(JSON.stringify(shape_properties));
newShape = new google.maps.Circle({
center:new google.maps.LatLng(array_shapes_object[counter].center.d, array_shapes_object[counter].center.e),
radius:array_shapes_object[counter].redius,
zIndex:array_shapes_object[counter].zIndex,
fillColor:array_shapes_object[counter].fillColor,
fillOpacity: 0.15,
strokeColor: '#FF0000',
strokeWeight: 1
});
一切都还可以。但我有一个大问题。 请看这一行:

center:new google.maps.LatLng(array_shapes_object[counter].center.d, array_shapes_object[counter].center.e),
这是圆心,包含纬度和经度,它保存在数据库中,如下所示:

“中心”:{“k”:32.9372338139709,“A”:50.91888427734375}

所有属性都保存在数据库中,如下所示:

{“users”:“user1”,“center”:{“k”:32.9372338139709,“A”:50.91888427734375},“redius”:25644.7738046513,“type”:“circle”,“zIndex”:2,“fillColor”:“#FF0000”,“name”:“circle”}

我的问题就是: 有时圆心由k等保存在数据库中: “中心”:{“k”:32.9372338139709,“A”:50.91888427734375}

但有时它会用d和e而不是k和A保存,如下所示: “中心”:{“d”:32.9372338139709,“e”:50.91888427734375}


当我读它画圆圈时,它会显示一个错误。我确信这个问题与GoogleMapsV3有关,而且看起来它们有时会更改变量的名称。如何修复它?

您无法存储这些属性,这些属性的名称(表示
google.maps
-类实例,如
LatLng
LatLngBounds
)不一致

您需要自己的格式/方法来存储和恢复这些数据(通过API提供的方法获取,例如
lat()
lng()
,用于LatLng)


请参阅以获取可能的解决方案

如果我可以列出对象中变量的名称,我想我可以修复它。有人能教我怎么做这样的事吗?