Convert object to string in firefox

I want to convert Geo Location Position Objectto String, so I can save it in localStoragefor future reference.

Now i have done below methods

$.toJSON(position)
JSON.stringify(position) // position is the object which return from Geo Location Success callback
jQuery.stringify(position)

Using all of the above, I cannot get it Stringin Firefox

Also checked out this one , but it didn't help as such

Firefox Console Result

enter image description here

Chrome console result

enter image description here

Demo link usingjQuery.stringify(position)

+3
source share
1 answer

This post explains why this happens in FF, but not in Chrome.

As a workaround, you can:

navigator.geolocation.getCurrentPosition(function(position) {
    var myPosition={timestamp: position.timestamp,
                    latitude:position.coords.latitude,
                    longitude:position.coords.longitude,
                    altitude:position.coords.altitude,
                    ...
                    }
    localStorage.position=JSON.stringify(myPosition);

});
+2
source

All Articles