离子清洁谷歌地图应用程序

时间:2015-04-20 21:08:23

标签: google-maps cordova ionic

我遇到谷歌地图的问题。在第一个实例中,整个负载正确,但第二个映射未加载。我认为这将解决一些方法,但没有。我已经采取这个来清除地图。

var map = document.getElementById("mapa_ubicacion");
google.maps.event.trigger(map, 'resize');

每次使用移动设备的相机拍照时,都会加载此地图,这是您可以多次占用的原因。

$scope.cargarUbicacion = function () {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
  .getCurrentPosition(posOptions)
  .then(function (position) {
    var latitud_actual  = position.coords.latitude
    var longitud_actual = position.coords.longitude
    var mapOptions = {
              center: new google.maps.LatLng(latitud_actual, longitud_actual),
              zoom: 15,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              scrollwheel: false
          };
          map = new google.maps.Map(document.getElementById("mapa_ubicacion"), mapOptions);
          $scope.setMarker(map, new google.maps.LatLng(latitud_actual, longitud_actual), 'Yo', '');
  }, function(err) {
    // error
  });


var watchOptions = {
  frequency : 1000,
  timeout : 3000,
  enableHighAccuracy: false // may cause errors if true
};

var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
  null,
  function(err) {
    // error
  },
  function(position) {
    var latitud_actual  = position.coords.latitude
    var longitud_actual = position.coords.longitude
    var mapOptions = {
              center: new google.maps.LatLng(latitud_actual, longitud_actual),
              zoom: 15,
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              scrollwheel: false
          };
          map = new google.maps.Map(document.getElementById("mapa_ubicacion"), mapOptions);
          $scope.setMarker(map, new google.maps.LatLng(latitud_actual, longitud_actual), 'Yo', '');
});
watch.clearWatch();
}

1 个答案:

答案 0 :(得分:1)

尝试在控制器的初始函数中创建单个地图实例,并将地图对象添加到范围。然后只更新方法中的地图位置。这有助于我解决类似的问题。

    $scope.init = function() {

        var mapOptions = {
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            scrollwheel: false
       };

       var map = new google.maps.Map(document.getElementById("mapa_ubicacion"), mapOptions);
       $scope.map = map;
    }

   $scope.init();
})

在您的方法中执行以下操作:

//set map center with your coords on $scope.map
$scope.setMarker($scope.map, new google.maps.LatLng(latitud_actual, longitud_actual), 'Yo', '');