简体   繁体   English

带有选项卡的Angular / Ionic Framework Google Maps

[英]Angular / Ionic Framework Google Maps with Tabs

I have been stuck on this for 2 days. 我已经坚持了两天。 Hopefully someone can help me out a bit or point me in the right direction. 希望有人可以帮助我一点,或指出正确的方向。

I am using ionic framework and ion-tabs for a listing page, one tab shows the description another is to load a map of the lat / lon I get from json. 我在列表页面使用ionic框架和ion-tabs,一个选项卡显示了描述,另一个选项卡是加载从json获取的经/纬度图。

I cannot get google maps to load in the second tab. 我无法在第二个标签中加载Google地图。 It will load up fine in the first tab or initial view. 它将在第一个标签或初始视图中正常加载。 I think it's because the map div is hidden or not rendered when in tab view. 我认为这是因为在选项卡视图中地图div被隐藏或未呈现。

I remember for bootstrap I had this issue with tabs and had to do a work around something like 我记得在进行引导时遇到选项卡问题,并且不得不做一些类似的工作

 $("a[href='#maptab']").on('shown.bs.tab', function(){
     mapInitialize();
 }
 });

^ Which basically inits the map. ^基本上是初始化地图。 How to do this with ionic though? 离子如何做到这一点?

Basically, I need the map to load into the second tab when entered. 基本上,输入地图后,我需要将地图加载到第二个标签中。

I created a codepen below you can see it loads fine on home, but on about it doesnt load up. 我在下面创建了一个Codepen,您可以看到它在家里可以很好地加载,但是大约不会加载。 For about I am calling in MapCtrl 关于我打电话给MapCtrl

 <ion-tab title="About" icon="ion-ios-information" href="#/tab/about" ng-controller="MapCtrl">

https://codepen.io/anon/pen/zBWJzw https://codepen.io/anon/pen/zBWJzw

Any suggestions or help would be appreciated. 任何建议或帮助,将不胜感激。

I guess the way I was calling the controller was the issue. 我猜我打电话给控制器的方式就是问题。 If anyone has a similar problem, below is what I did. 如果有人遇到类似的问题,以下是我的工作。

I assigned a separate controller for maps (eg MapCtrl and then called it from the tab like. 我为地图分配了一个单独的控制器(例如MapCtrl,然后从类似的标签中调用它。

        <ion-tab title="Map" icon-on="ion-earth" icon-off="ion-earth">
            <ion-nav-view name="tab-map">
                <ion-content ng-controller="MapCtrl" ng-init="initialize()">

If you are testing maps on an iOS simulator and get a blank screen you need to make sure you whitelist the google script url as well. 如果要在iOS模拟器上测试地图并显示空白屏幕,则需要确保将Google脚本网址也列入白名单。

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

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