Google地图无法使用标签Ionic

时间:2016-03-15 13:51:51

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

我在Ionic项目上创建了标签。当我从其他网址标签访问谷歌地图时,它无法正常工作,但当我直接访问它时,它可以正常工作。

1 个答案:

答案 0 :(得分:0)

首先是离子部分: 显示地图的标签是:     

当用户选择选项卡时,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);
    };
})

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

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