Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,
I am working on a web application which is using google map api.
The problem is that when the page will refresh than creating a new map object.

So I want to store this map object in a cookie on first time page load.
If cookie will be null then "setCookee" if cookie is not null then map object get value form "Cookie".

here is sample code.
var map
var lati = 25; // initial latitude
var longi = 76; // initial longitude
var latlng = new google.maps.LatLng(lati, longi);
var opt =
{
center: latlng,
zoom: 9,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var mapCookieCheck=getMapCookie("mapCookie");
if(mapCookieCheck=='undefined' ||mapCookieCheck=="")
{
map = new google.maps.Map(document.getElementById("map"), opt);
setMapCookie("mapCookie", map, 365);
}
else
{
debugger
map = mapCookieCheck;
}


function setMapCookie(cName, cValue, expDays)
{
debugger
var d = new Date();
d.setTime(d.getTime()+ (expDays *24*24*60*1000));
var expires="expires="+d.toUTCString();
document.cookie= cName +"=" + cValue + ";" + expires;
}


Please resolve this problem.
Posted
Updated 31-Dec-15 23:49pm
Comments
Dave Kreskowiak 1-Jan-16 10:41am    
Considering a cookie is a small text file, how are you going to store a "map object" in it? You don't store an object. You store either the information required to recreate it or a serialized version of it.
RedDk 1-Jan-16 14:44pm    
Think along the lines of "writing" a cookie first. Above you assume there's something to "set". Have you identified "script type"? This is the mime pattern (if I'm not mistaken ... please correct me anybody if I'm wrong here)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900