0

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?

Parsa Soroori
  • 63
  • 3
  • 12
  • I think I can fix it if I could list the name of variables in an object. Can anybody show me how to do something like this? – Parsa Soroori Mar 12 '14 at 10:43

1 Answers1

2

You can't store these properties, the names of these properties(that represent google.maps-class-instances like LatLng or LatLngBounds) are not consistent.

You'll need your own format/methods to be able to store & restore these data(fetched via the methods provided by the API, e.g. lat() and lng() for a LatLng )

See How to save a Google maps overlay shape in the database? for a possible solution

Community
  • 1
  • 1
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201