卸载谷歌地图API?地图、API

2023-09-10 17:54:01 作者:夏夜流萤

我有一个使用Ajax加载的子页面和这些子页面中的一个包含了谷歌地图的主网页,所以它加载使用谷歌地图API的<脚本> 标签:

I have a main page that uses ajax to load subpages and one of these subpages contains a google map, and so it loads the google maps api using the <script> tag:

&LT;脚本类型=文/ JavaScript的 src="http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE">

我注意到,这个加载了一堆的CSS和JS文件到我的两个主网页和子页面。当我在我的主网页点击不同的链接,我希望能够卸载所有这些文件并删除创建的任何JS对象,即,清理一切,并返回到原来的状态。有没有办法做到这一点?

I noticed that this loads a bunch of css and js files into both my main page and subpage. When I click on a different link in my main page, I want to be able to unload all of these files and remove any js objects that were created, i.e., clean up everything and return to the original state. Is there any way to do this?

推荐答案

在回答你的问题其实是更复杂一点比你想象的。一个很好的问题的答案,并设置了处理许多有关详情载于:什么是正确的方法销毁地图实例。

The answer to your question is actually a bit more complicated than you might think. A good question and set of answers that deal with many of the related details are at: What is the Proper Way to Destroy a Map Instance?.

我不知道从你的问题,但它听起来像是你可能已经创建了一个网页,加载谷歌地图API的一个以上的时间(或可能,这取决于用户的选择),你应该避免完全。谷歌承认有与重装地图相关联的内存泄漏缺陷,并强烈建议不要多地图重载。谷歌基本上不支持多地图负荷的用例。

I'm not sure from your question, but it sounds like you may have created a page that loads the Google Maps API more than one time (or could, depending on user choices) and you should avoid that entirely. Google admits there are memory leak bugs associated with reloading the map and strongly recommends against multiple map reloads. Google essentially does not support multiple map load use cases.

检查出的一些信息可在提问环节包括以上;它包含了一些很好的讨论和信息。

Check out some of the information available at the question link included above; it contains some good discussion and information.

查看谷歌地图API受理时间2012年5月9日视频克里斯布罗德福特和卢克马埃从谷歌讨论:他们不支持用例涉及重装地图,该API的目的是要加载只有一次,他们承认有内存泄露问题。设置播放到〜12:50,查看有关节破坏地图,问题重装地图,他们提供,以避免问题的​​建议。首先,如果你一定要隐藏,然后显示一个地图,他们推荐重新使用一个单一的地图实例。

Check out the Google Maps API Office Hours May 9 2012 Video where Chris Broadfoot and Luke Mahe from Google discuss: that they don't support use cases that involve reloading the map, that the API is intended to be loaded only once, and their acknowledgement that there is a memory leak bug. Set the playback to ~12:50 to view the section about destroying the map, problems with reloading the map, and suggestions they offer to avoid problems. Primarily, if you must hide and then show a map, they recommend reusing a single map instance.