Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:12:30+00:00 2026-06-02T04:12:30+00:00

I’m attempting to store a Google Map’s center point to a cookie and restore

  • 0

I’m attempting to store a Google Map’s center point to a cookie and restore the map to the last position the next time the page is loaded.

Sure I can save the latitude and longitude into the cookie as a string or a serialized array or something but I’m curious if I can just JSON serialize the Google Maps LatLng object to the cookie and then just restore it at a later time.

I’m using JQuery and this library: http://code.google.com/p/cookies/

I set the cookie with a LatLng from the map:

$.cookies.set( 'map_center', map.getCenter());

And Then I try to read it out expecting the serialization/deserialization will restore my object…

var centerpointFromCookie = $.cookies.get('map_center);
map.setCenter(centerpointFromCookie);

But it appears the object type is not preserved. In the script console this is what the LatLng Object looks like before it is serialized and stored in the cookie:

map.getCenter()
O
$a: 151.21950000000004
Za: -33.8688
__proto__: O
constructor: function O(a, b, c) {a-=0;b-=0;c||(a=Bd(a,-90,90),b=Cd(b,-180,180));this.Za=a;this.$a=b;}
equals: function (a) {return!a?k:Dd(this.lat(),a.lat())&&Dd(this.lng(),a.lng());}
lat: function () {return this[a];}
lng: function () {return this[a];}
toString: function () {return"("+this.lat()+", "+this.lng()+")";}
toUrlValue: function (a) {a=Hd(a)?a:6;return ae(this.lat(),a)+","+ae(this.lng(),a);}
__proto__: Object

And this is what it looks like afterwards:

centerpointFromCookie
Object
$a: 151.21950000000004
Za: -33.8688
__proto__: Object
__defineGetter__: function __defineGetter__() {
__defineSetter__: function __defineSetter__() {
__lookupGetter__: function __lookupGetter__() {
__lookupSetter__: function __lookupSetter__() {
constructor: function Object() {
hasOwnProperty: function hasOwnProperty() {
isPrototypeOf: function isPrototypeOf() {
propertyIsEnumerable: function propertyIsEnumerable() {
toLocaleString: function toLocaleString() {
toString: function toString() {
valueOf: function valueOf() {

Do I need to cast the object to the GoogleMapsLatLng type when deserializing? I know I could just store the values but I’d like to understand how to properly serialize a small object like this out to a cookie.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:12:33+00:00Added an answer on June 2, 2026 at 4:12 am

    Just serialize the lat/lng.

    Serializing the object’s prototype or function properties doesn’t work well because they have to be stringified for that, and when you try to turn the string back into a function, you will lose all references to variables that were visible in the original scope but are not visible now. And you can’t easily guess how to manually restore the right prototype later, because prototypes can change at any time. And you’ll be tying your object to that specific version of the LatLng prototype which will not be fun when the API gets updated.

    Not to mention serializing that much data will take up a lot more space in the cookie than plain lat/lng.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.