Angularjs Ionic google地图仅在首次加载视图时显示
我的ionic应用程序从数据库中获取一些位置,并根据这些数据生成地图Angularjs Ionic google地图仅在首次加载视图时显示,angularjs,google-maps,ionic-framework,ionic,Angularjs,Google Maps,Ionic Framework,Ionic,我的ionic应用程序从数据库中获取一些位置,并根据这些数据生成地图 $scope.$on('$ionicView.beforeEnter', function(){ // get event data Events.getEvent($stateParams.eventId).then(function(data){ $scope.eventInfo = data[0]; $ionicLoading.hide(); // get locat
$scope.$on('$ionicView.beforeEnter', function(){
// get event data
Events.getEvent($stateParams.eventId).then(function(data){
$scope.eventInfo = data[0];
$ionicLoading.hide();
// get location data
if(data[0].location){
Locations.getLocation(data[0].location).then(function(data){
$scope.location = data[0];
// call the map
$scope.initialize($scope.location.locstreet, $scope.location.zip, $scope.location.ort);
});
}
});
检索数据后,脚本调用initialize函数:
function initialize(strasse, plz, ort) {
var map = new google.maps.Map(document.getElementById('map'),{
zoom: 14
});
img = new google.maps.MarkerImage("img/icon.png", null, null, null, new google.maps.Size(30,30));
var geocoder = new google.maps.Geocoder();
var address = strasse + ", " + plz + " " + ort;
geocoder.geocode({'address': address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: img
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
这在我第一次导航到这个视图时效果很好。如果我离开视图,返回到具有其他数据的同一视图,地图将显示灰色,右下角带有谷歌徽标
我认为这可能是因为多重初始化
var-map
。但是如果我在函数之外声明var-map
,它也不起作用。将以下内容添加到您的状态提供程序中:缓存:false(当您定义映射时)。
这对我很有用。是的,这件事发生在我身上,让我很生气。问题是它的Ever4谷歌地图无法进行动态渲染,因此如果你的地图隐藏,通常不会进行渲染。如果你能用一些JSFIDLE或plunkr来解决这个问题,我可以尝试一鼓作气地解决,最好的方法是使用谷歌地图的指令,如本文@Javierif you can post your solution?。。我也有同样的问题。