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.
Google maps has a simple way to do this: center = map. getCenter.
getBounds() in Google Maps API v3 But in API v3 you will get “bounds is undefined” error. So to get our latitude and longitude we need to move getBounds(), to some event listener. Description of bounds_changed in documentation is: “This event is fired when the viewport bounds have changed.”
Sets the viewport to contain the given bounds. Note: When the map is set to display: none , the fitBounds function reads the map's size as 0x0, and therefore does not do anything. To change the viewport while the map is hidden, set the map to visibility: hidden , thereby ensuring the map div has an actual size.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With