【发布时间】:2014-04-16 10:12:25
【问题描述】:
我使用 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));
我有一个名为 shape_properties 的变量,我将所有圆形属性保存在其中,然后使用 JSON.stringify(shape_properties) 将其更改为字符串,最后将此字符串保存到数据库。
当我想在地图上画这个圆圈时,我会使用类似的东西。我的意思是从数据库中读取这些包含圆形属性的字符串,然后使用JSON.parse(array_shapes_string[counter]) 将其更改为对象,最后使用以下代码绘制它:
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 和 A 保存在数据库中,例如: "中心":{"k":32.9372338139709,"A":50.91888427734375}
但有时它会使用 d 和 e 而不是 k 和 A 保存,如下所示: "中心":{"d":32.9372338139709,"e":50.91888427734375}
当我阅读它来绘制圆圈时,它会告诉我一个错误。我确定这个问题与 Google maps v3 有关,而且似乎它们有时会更改变量的名称。我该如何解决?
【问题讨论】:
-
如果我可以列出对象中变量的名称,我想我可以修复它。谁能告诉我如何做这样的事情?
标签: javascript json google-maps-api-3