Reputation: 5148
I have an app that saves google map markers, I basically save the lat lng coordinates/vriables in an array, then I save it in my mongodb. When I reload those markers, I loop in the array and create markers from the saved lat lng variable.
My problem is that when I saved my markers the first time, a lat was called Pa and a lng Oa, then 1 month ago, I save markers, and then try to load them, but my loop doesn't recognize the lat lng variables, they were changed to Sa, Ta. So I changed my client code to pull variables of Sa, Ta instead, no big deal.
Today, I save another array of marker, try to load it, and it doesn't work, again their native google api variable name are changed to lat Ua and lng Va ... My client code doesn't work for any new saved marker.
I'm obviously not saving markers the "google" way, what am I doing wrong?
Thank you
Upvotes: 0
Views: 149
Reputation: 7228
mongodb is unsuitable for storing lat/lng as there is no arbitrary precision or decimal data type in BSON. mongo data types
Upvotes: 0
Reputation: 77474
You should not rely on the variable names of minimized code. Call them "lat" and "lon" or something like that. The internal names such as Pa
are potentially lost on each recompilation. In particular, they will likely change when Google fixes a bug or releases a new version of the API.
So don't just blindly encode the marker objects. Convert them to a stable representation that you control yourself (and not the automatic code compiler of Google maintains and changes at will).
Upvotes: 3
Reputation: 26873
Since the API seems to be changing every once in a while you might want to decouple your implementation from it. Store lat and lon however you want and then write adapter that maps that data to Google API suitable and back on save.
Upvotes: 0