简体   繁体   中英

Google Maps API function map.getCenter()

I'm saving the Zoom and Location of the Google Map API setting in cookies as the user adjusts his map. When they come back the map is at the same place. The function works most of the time:

   var h = JSON.stringify(map.getCenter(), null, 2);
   jQuery.cookies.set("YD44635center",h,cookieOptions);

On the decode side using:

    locationVar = jQuery.cookies.get("YD44635center");
    var temp = "";
    // for testing:
    for(var x in locationVar){
        temp += x + "\n";
    }
    alert(temp);

To see what I'm getting, most of the time, is:

   Qa;
   Pa;

So I set my code to load the map with those variables and everything is fine. Then one day the page stops working and the parameters returned do not have a "Q" anymore like in Qa but an "O" like in Oa. So I changed the code and it worked for a day and then what Google was sending changed back to the Qa. I changed it back.

Time goes by. Now today the code start working intermittently and I put that debug thing back in and now instead of "Pa" on the second variable I'm getting "Ra". Not continuously but mostly. What's up. It's happening on two different browsers the same way.

Use API functions and save the required data, not the structure

var c = map.getCenter();
jQuery.cookies.set("YD44635center", c.lat() + ',' 
                                  + c.lng() + ',' + map.getZoom(), 
                                                     cookieOptions);

and read it as

var temp = jQuery.cookies.get("YD44635center").split(',');

Google is changing the names of the internal variables from time to time Error on Latitude and Longitude - Google Maps API JS 3.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM