0

我正在使用 angular-ui.github.io/angular-google-maps/

我使用推荐的延迟加载技术,我的 app.js 中有这个:

.config(function(uiGmapGoogleMapApiProvider) {
  uiGmapGoogleMapApiProvider.configure({
    //    key: 'your api key',
    v: '3.20' //defaults to latest 3.X anyhow
    //libraries: 'weather,geometry,visualization'
  });
})

在我的控制器中的某个时刻,我执行以下操作:

var uiGmapGoogleMapApiTimer = $timeout(function() {
  reject("uiGmapGoogleMapApi didn't respond after 10 seconds.");
}, 5000);

console.log('DUDE.01');
uiGmapGoogleMapApi.then(function(maps) {
  console.log('DUDE.02');
  $timeout.cancel(uiGmapGoogleMapApiTimer);
  geocoder = new google.maps.Geocoder();
  resolve(geocoder);
}, function(err) {
  console.log('DUDE.03');
});

因此,当我离线时,计时器将启动,我将用户发送回登录页面。(最初我只是简单地退出应用程序。它适用于android,但在iOS 中它不起作用,它实际上被Apple 禁止)。

所以...这就是为什么现在我将其发送回登录页面。

现在,在登录页面中,我重新激活了我的 wifi ......一旦我回到(应该)显示地图的页面......它就坏了。uiGmapGoogleMapApi.then 的成功处理程序永远不会被调用。(打印 Dude.01,但打印 Dude.02 和 Dude.03)。

所以......那个页面(错误地)认为设备仍然断开连接。

我想这是因为谷歌地图 javascripts 的加载只完成了一次(在加载期间——这就是为什么如果我关闭我的应用程序并返回,事情会运行得很好)。

所以......这并不是真正的延迟加载(?)。或者......如果它是延迟加载,它似乎不支持......尝试第二次加载它(如果第一次由于连接而失败)。

有没有人足够熟悉 angular-ui.github.io/angular-google-maps/ 的源代码来建议这个问题的解决方案是什么?


我查看了放入库代码中的日志......我得出结论:我需要在第二次调用 uiGmapGoogleMapApi.then 时重新执行第 183 行......目前它没有。当我启动我的应用程序并从一开始就有互联网连接时,它只会被第一次调用。

在此处输入图像描述


根据我从这个关于“提供者”的文档中了解到的内容,我需要在第二次尝试使用 uiGmapGoogleMapApi 时(就在之前)重新实例化它。

https://docs.angularjs.org/api/auto/service/ $provide

那正确吗?如何?


看起来我在这里与提供者缓存作斗争。因为我在控制器中使用依赖注入来获取对 uiGmapGoogleMapApi 的引用。(我有 .controller('myctrl', function(uiGmapGoogleMapApi) {...})

我可能需要的是:

.controller('myctrl', function() {
   var uiGmapGoogleMapApi = $injector.get('uiGmapGoogleMapApi');
   //or something along that line maybe
 })

我刚试过,还是不行。

请帮忙。

谢谢,拉卡


好吧,我的“解决方案”是:我不去登录页面,而是通过将窗口对象的当前 url 设置为 index.html 来简单地刷新应用程序。

4

0 回答 0