Google Maps API函数map.getCenter() [英] Google Maps API function map.getCenter()

查看:164
本文介绍了Google Maps API函数map.getCenter()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户调整地图时,我会在Cookie中保存Google Map API设置的缩放和位置。当他们回来时,地图就在同一个地方。该函数大部分时间都有效:

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);

在解码方面使用:

    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;

所以我设置我的代码来加载带有这些变量的地图,一切都很好。然后有一天
页面停止工作,返回的参数不再像Qa那样有Q,而是像Oa那样的O。所以我改变了代码,它工作了一天,然后Google发送的内容改回了Qa。我改回来了。

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.

时间流逝。现在,代码开始间歇性地工作,我把调试的东西放回来,而现在而不是Pa在第二个变量上我得到Ra。不是持续但主要是。这是怎么回事。它以相同的方式在两个不同的浏览器上发生。

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.

推荐答案

使用API​​函数并保存所需的数据,而不是结构

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);

并将其读作

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

Google正在不时更改内部变量的名称
纬度和经度错误 - Google Maps API JS 3.0

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

这篇关于Google Maps API函数map.getCenter()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆