Android 谷歌地图图块无法在“背面”加载按钮点击

发布于 2024-10-06 10:20:36 字数 336 浏览 8 评论 0原文

我有一个使用 Google 地图的 Android 应用程序。我的第一个活动启动了一个带有一些可点击图标的地图视图。单击图标时,将使用不同的地图启动新活动(意图)。然后,我从新地图中单击后退按钮,返回到我的第一张地图。但是,当我开始缩放或在地图中移动时,只会显示最初加载的图块。我怎样才能改变这个?

如果您更改手机方向,地图将刷新,然后它会正常运行(因为应用程序已重新启动),因此我添加了 android:configChanges="orientation" 以停止方向更改时重新启动。我添加这一点是因为我不想再次重新加载所有标记(使用网络服务并且可能需要一些时间)。

我只想在单击“返回”原始地图时加载图块。有什么想法吗?

I have an android application that uses Google Maps. My first activity starts a mapview with some clickable icons. When an icon is clicked, a new activity (intent) is started with a different map. From the new map I then click the back button which takes me back to my first map. However, when I start zooming or moving around in the map, only the tiles that originally loaded will show up. How can I change this?

If you change the phone orientation the map will refresh and then it behaves normally (becuase the app restarted) so I added android:configChanges="orientation" to stop the restarting on orientation change. I added that because I don't want to reload all the markers again (uses a web service and can take some time).

I just want the tiles to load when I click "back" to the original map. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凑诗 2024-10-13 10:20:36

我最近也遇到了这个问题!检查日志 - 您可能会收到类似“IllegalStateException:连接池关闭”的错误。也和我一样,您找到的唯一答案似乎是针对那些没有正确设置 Google API 密钥的人。 :-\

我最终遇到了此链接。 (您通常需要登录 Google 帐户才能阅读这些帖子)

似乎存在一个错误,仅允许每个应用程序执行一项地图活动。我猜这与地图刷新有关。我通过在加载新地图活动后完成每个地图活动来解决这个问题,从而导致当用户返回该活动时重新加载整个活动。这并不理想,但到目前为止对我来说效果很好。

更详细地说:

  1. 保存您想要稍后检索的地图的所有信息。首先想到的是地图中心和地图缩放。将其放在全局某个位置,或者按照您的意图将其传递。

  2. 启动第二个活动的 Intent 后,对第一个活动调用 finish()。如果您希望这两个地图向用户显示为同一个地图,那么您需要取消启动新活动时默认发生的滑动过渡。为此,请在 finish() 之后立即调用此行:

overridePendingTransition(0, 0);

  1. 当您的第二个地图活动需要完成时,如果需要,请重复步骤 1,然后加载第一个地图活动使用与步骤 2 相同的方法返回。2 中的代码将放入活动的 onBackPressed() 方法中,以及其他适当的位置(也许您有取消按钮或其他东西)。

  2. 在第一个活动的 onCreate 中,确保检查上次查看该活动时保存的内容,并适当修改地图。

也许这很冗长,但我经常使用这个网站,而且我总是很欣赏那些说得太多的答案,而不是那些说得太少的答案,哈哈!

I ran into this problem recently as well! Check your log - you're probably getting an error along the lines of "IllegalStateException: Connection pool shut down." Also like me, the only answers you found seemed to be for people who hadn't set up their Google API key right. :-\

I eventually ran into this link. (You usually need to be signed in to your Google account to read these posts)

It appears as though there's a bug that only allows one map activity per application. Something to do with the map refreshing, I guess. I got around it by finishing each map activity after loading the new one, causing the activity to be reloaded in its entirety when the user returns to it. It's not ideal, but it's worked well for me so far.

In some more detail:

  1. Save any information about the map you want to retrieve later. Map center and map zoom first come to mind. Put it somewhere global, or pass it in with your intent.

  2. After launching the intent for the second activity, call finish() on the first one. If you want the two maps to appear to the user as the same map, then you'll want to kill the sliding transition that occurs by default when a new activity is started. Do that by calling this line immediately after finish():

overridePendingTransition(0, 0);

  1. When your second map activity needs to finish, repeat step 1 if needed and then load the first map activity back using the same method as step 2. The code from 2 would go in the onBackPressed() method of the activity, and wherever else its appropriate (maybe you have a cancel button or something).

  2. In the onCreate of the first activity, make sure you check for stuff that's been saved from the last time that activity was being viewed and modify your map appropriately.

Maybe that was verbose, but I use this site a lot and I always appreciate the answers that say too much a lot more than the ones that say too little, haha!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文