I used JSON method to save Google overlays in database. For example I save a circle in the database by this code:
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));
I have a variable named shape_properties and I save all circle properties inside of it and then change it to string by using JSON.stringify(shape_properties)
and finally save this string to database.
And when I want to draw this circle on the map, I use something similar. I mean read these string contains circle properties from database and then change it to object by using JSON.parse(array_shapes_string[counter])
and finally draw it by using this code:
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
});
All are OK yet. But I have a big problem. Look at this line:
center:new google.maps.LatLng(array_shapes_object[counter].center.d, array_shapes_object[counter].center.e),
This is the center of circle contains latitude and longitude and it is saved in database like this:
"center":{"k":32.9372338139709,"A":50.91888427734375}
And all properties are saved in database like this:
{"users":"user1,","center":{"k":32.9372338139709,"A":50.91888427734375},"redius":25644.7738046513,"type":"circle","zIndex":2,"fillColor":"#FF0000","name":"Circle"}
My problem is exactly this: Sometimes center of circle is saved in database by k and A like: "center":{"k":32.9372338139709,"A":50.91888427734375}
But sometimes else it will save with d and e instead of k and A like this: "center":{"d":32.9372338139709,"e":50.91888427734375}
And when I read it to draw the circle it will show me an error. I'm sure this problem related to Google maps v3 and it seems they sometimes change the name of variables. How can I fix it?