简体   繁体   English

sessionStorage和Google Maps

[英]sessionStorage and Google Maps

I'm attempting to use Web Storage (sessionStorage in particular) to save an instance of a Google Map and markers thats being generated based on a user's Postal Code. 我正在尝试使用Web存储(尤其是sessionStorage)来保存Google Map实例和基于用户的邮政编码生成的标记。

The functionality of this is: 其功能是:

  1. User searches for 'store locations' with a postal code. 用户使用邮政编码搜索“商店位置”。
  2. Map generates, with markers on each found location. 地图会生成,并在每个找到的位置标记。
  3. User clicks on a result/marker - linking to a 'store location landing page'. 用户单击结果/标记-链接到“商店位置登录页面”。
  4. User can return to search. 用户可以返回搜索。
  5. Their searched map with results/markers should remain. 他们搜索的带有结果/标记的地图应保留。

Is this possible with sessionStorage? sessionStorage是否可能?

Thanks 谢谢

Yes, this is possible, but sessionStorage is cleared out when the window is closed. 是的,这是可能的,但是在关闭窗口时会清除sessionStorage。 If you want them to stay even when the window is closed, you should use localStorage . 如果您希望它们即使在关闭窗口后仍保持不变 ,则应使用localStorage

To save data into sessionStorage, you'd use syntax like the following: 要将数据保存到sessionStorage中,可以使用如下语法:

sessionStorage.setItem('name_of_key', 'value_for_key');

For more help with sessionStorage, check out the MDN page . 有关sessionStorage的更多帮助,请查看MDN页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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