【问题标题】:Google Maps not working on tab Ionic谷歌地图无法在 Ionic 选项卡上运行
【发布时间】:2016-07-01 00:11:36
【问题描述】:

我在 Ionic 项目上创建标签。当我从另一个 url 选项卡访问谷歌地图时,它不工作,但当我直接访问它时,它工作。

【问题讨论】:

标签: google-maps ionic-framework cordova-plugins


【解决方案1】:

首先是离子部分: 显示地图的选项卡是:

当用户选择选项卡时,Ionic 会调用 refreshMap()。 refreshMap() 是:

.controller('MainCtrl', function($scope) {
    $scope.refreshMap = function() {
        setTimeout(function () {
            $scope.refreshMap_();
        }, 1); //Need to execute it this way because the DOM may not be ready yet
    };

    $scope.refreshMap_ = function() {
        var div = document.getElementById("map_canvas");
        reattachMap(map,div);
    };
})

我已经实现了 reattachMap() 查看 Map.init() 方法:

function reattachMap(map,div) {
    if (!isDom(div)) {
        console.log("div is not dom");
        return map;
    } else {
        map.set("div", div);

        while(div.parentNode) {
        div.style.backgroundColor = 'rgba(0,0,0,0)';
        div = div.parentNode;
        }

        return map;
    }
}

function isDom(element) {
    return !!element &&
    typeof element === "object" &&
    "getBoundingClientRect" in element;
}

就是这样,现在当用户切换回地图选项卡时,它就会在那里。

请参考这里。 (https://github.com/mapsplugin/cordova-plugin-googlemaps/issues/256/#issuecomment-59784091)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-14
    • 2012-12-10
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 2012-11-18
    • 2012-11-22
    相关资源
    最近更新 更多