Google 地图 API 函数 map.getCenter()
当用户调整地图时,我将 Google Map API 设置的缩放和位置保存在 cookie 中。当他们回来时,地图位于同一个地方。该函数在大多数情况下都有效:
var h = JSON.stringify(map.getCenter(), null, 2);
jQuery.cookies.set("YD44635center",h,cookieOptions);
在解码端使用:
locationVar = jQuery.cookies.get("YD44635center");
var temp = "";
// for testing:
for(var x in locationVar){
temp += x + "\n";
}
alert(temp);
要查看我得到的,大多数情况下是:
Qa;
Pa;
所以我设置代码来加载带有这些变量的地图,一切都很好。然后有一天 页面停止工作,返回的参数不再像 Qa 中那样带有“Q”,而是像 Oa 中那样带有“O”。所以我更改了代码,它工作了一天,然后 Google 发送的内容更改回了 Qa。我又改回来了
时间流逝。现在,今天代码开始间歇性地工作,我将调试内容放回原位,现在第二个变量上的“Pa”不再是“Ra”。不是连续的,而是大部分。这是怎么回事。它以相同的方式在两个不同的浏览器上发生。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 API 函数并保存所需的数据,而不是结构
并读取它,因为
Google 会不时更改内部变量的名称
纬度和经度错误 - Google Maps API JS 3.0
Use API functions and save the required data, not the structure
and read it as
Google is changing the names of the internal variables from time to time
Error on Latitude and Longitude - Google Maps API JS 3.0